CSS Specific for Internet Explorer 188
As much as we don't like to deal with the IE bugs, we still have to face it because your boss and visitors are still using Explorer. It gets frustrating when different versions of Explorer displays web pages differently due to the inconsistent rendering engine. We typically use IE conditional comments to fix the IE issues. But there are more ways than the conditional comments...
#1 IE Conditional Comments
IE conditional comment is probably the most commonly used to fix the IE bugs for specific versions (IE6, IE7, IE8). Below are some sample code to target different versions of Internet Explorer:
<!--[if IE 8]>= IE8<!--[if lt IE 8]>= IE7 or below<!--[if gte IE 8]>= greater than or equal to IE8
<!--[if IE 8]>
<style type="text/css">
/* css for IE 8 */
</style>
<![endif]-->
<!--[if lt IE 8]>
<link href="ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
#2 CSS Rules Specific to Explorer (IE CSS hacks)
Another option is to declare CSS rules that can only be read by Explorer. For example, add an asterisk (*) before the CSS property will target IE7 or add an underscore before the property will target IE6. However, this method is not recommended because they are not valid CSS syntax.
- IE8 or below: to write CSS rules specificially to IE8 or below, add a backslash and 9 (
\9) at the end before the semicolon. - IE7 or below: add an asterisk (
*) before the CSS property. - IE6: add an underscore (
_) before the property.
.box {
background: gray; /* standard */
background: pink\9; /* IE 8 and below */
*background: green; /* IE 7 and below */
_background: blue; /* IE 6 */
}
#3 Conditional HTML Class
The third option, which was founded by Paul Irish, is to add an CSS class with the IE version to the HTML tag by using IE conditional comments. Basicially, it checks if it is IE, then add a class to the html tag. So to target specific IE version, simply use the IE class as the parent selector (eg. .ie6 .box). This is a clever way and it doesn't cause any validation errors.
<!--[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]-->
This is verry good.
In some cases you coud use !important marker to trick IE browsers. The advantage of using !important is that your CSS file remains valid.
Thanks for good concise post.
background: blue /; /* IE 9 */
background: blue \ 0 /; /* IE 9 (\ 0 /without space) */
And then he handed you the thirty-five 45
Great. We been having some problems with a Joomla site not displaying well in IE. Why has Microsoft had so much trouble with html over the years? ;-) . This article will be bookmarked and emailed to colleagues!
I do the same question. Unbelievable how so big company can still produce crap such as IE. Each new version, the problems remains. What the hell they do?
Great tip, no doubt.
Thank you very much for the clear tips to run the CSS file in IE.
Great tips. Thanks for bringing that out. It’s very helpful =) keep up!
going crazy with this different browser. why there is not a unique css code for all?
ohhhh nice i like this
Option 3 does not seem to work with IE9. any other suggestions?
Thanks in advance!
awesome bro keep it up
Hacks and Fixes for IE perpetuate the use of this obsolete browser and stagnate web page development. Do not use IE hacks. Encourage your site visitors to upgrade their browser.
Bikeman, spoken like a true self-centered, arrogant web developer. Grandma Gertie is NOT going to want to upgrade her browser. Hell, she barely was able to figure out the ‘computer thing’ and just learned how to check her email. If you’re a true professional, you will find a way to code the CSS to deal with IE. It’s part of our job. Deal with it. Supposedly, you know more than Grandma Gertie. Prove it.
Not only does Grandma Girtie now want to nor know how to upgrade their browser but MANY corporations were required to custom build their online applications for internal use for IE6 because it was such a BAD browser. Many of those companies don’t want to redesign their apps *again* and force their employees to use IE6 still to this day.
good, simple and its work with chrome, firefox and ie 6.
thanks.
Excellent post, really very helpful, thanks for sharing it here, i really found this useful for running the CSS file.
Thank you very much for this post :)))
IE still have so many problems with css, our site is working fine in IE7, IE8 but had some problem with IE9, didn’t expected IE9 to be worse than earlier IE :)
Thanks for the tips.
Thank you so much. Finding this post saved me from a frustrating font problem I had on my site with only IE9 . I used #2 (\9;)and it worked beautifully. This will definitely be a saved post in my tips folder. Cheers.
Wow… #2 \9 works like a charm… Thanks !
ads
Doesn’t work with px amounts?
right: 35px\9;
display: none\9;
is perfectly worked for me.
thanks a lot. :)