5 CSS tips and hacks for Internet Explorer
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->For example:
For example:
#element{
background: #46DE46;
border: solid 1px #36F;
width: 300px;
height: 2px;
margin: 30px 0;
overflow: hidden;
}Another issue with regards to element height is the min-height attribute that doesn’t work well with IE.
What you can do is this:
Only on the Internet Explorer will you have an element that is floated with a huge infuriating margin that follows in the same direction as the float, causing your web to end up with double the intended margin size.
Well, there’s a pretty useful tip you can apply to fix this particular IE bug. Simply apply the “display: inline†rule to your floated element.
An example would be this:
For IE browsers, you may apply this technique to center your block element. Do note whether your size sets is measured in percentages or in absolute values.
Centering an entire page’s contents:body{
text-align: center;
}
#container
{
text-align: left;
width: 960px;
margin: 0 auto;
}Fix 5) Universal IE 6 CSS
Using a special stripped down stylesheet that accommodates smooth CSS performance for all versions of the IE browser. I present to you, the universal IE 6 CSS command function.
For example:Next stop on the list let us focus on some nice hacks for CSS on the different web browsers.
A strong reminder: Hacks can be menacing, as they are non-standard exploits, you may not be able to predict the hack’s future behavior for updated browsers.You have your selector hacks:
/* IE6 and below */
* html #uno { color: blue }
/* IE7 */
*:first-child+html #dos { color: blue }
/* IE7, FF, Saf, Opera */
html>body #tres { color: blue }
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: blue }
/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: blue }
/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: blue }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: blue }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho { color: blue }
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez { color: blue }
}
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: blue }
}
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece { color: blue }
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: blue }
/* Everything but IE6-8 */
:root *> #quince { color: blue }
/* IE7 */
*+html #dieciocho { color: blue }
/* IE 10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
#veintiun { color: blue; }
}
/* Firefox only. 1+ */
#veinticuatro, x:-moz-any-link { color: blue }
/* Firefox 3.0+ */
#veinticinco, x:-moz-any-link, x:default { color: blue }
/* FF 3.5+ */
body:not(:-moz-handler-blocked) #cuarenta { color: blue; }
And you have your attribute hacks:
/* IE6 */
#once { _color: red }
/* IE6, IE7 */
#doce { *color: blue; /* or #color: red */ }
/* Everything but IE6 */
#diecisiete { color/**/: red }
/* IE6, IE7, IE8, but also IE9 in some cases :( */
#diecinueve { color: red\9; }
/* IE7, IE8 */
#veinte { color/*\**/: red\9; }
/* IE6, IE7 -- acts as an !important */
#veintesiete { color: red !ie; } /* string after ! can be anything */
/* IE8, IE9 */
#anotherone {color: red\0/;} /* must go at the END of all rules */
/* IE9, IE10 */
@media screen and (min-width:0\0) {
#veintidos { color: blue}
}