CSS Specific for Internet Explorer 154
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]-->
Nice Tutorial …
Nice advise! Thanks
Also, I would do IE fixes buried in the .js file. It’s radical and not too subtle, but has 2 advantages: none of the HTML/CSS code is polluted by IE fixes and we can use CSS3 selectors for IE with jQuery.
Good Article,
Thanks.
Why not use something like Modernizr that adds classes to the html tag (like what’s done in the HTML5 Boilerplate) to target specific versions of IE? I’ve found that to be the easiest solution for me.
Good!
Thanks.
Wow that was Cool for IE….and I a looking forward for more Cool IE CSS combination effects…
is this w3c standard ????
I have always had trouble making a good website design layout that is also compatible with IE. All other browsers are not a problem, but IE usually is the headache.
I find using a chunk of css to reset browser defaults helps a lot, even with ie7. We don’t support ie 6
yeah since I started using a reset stylesheet I have less problems.
very nice
it’ s really nice post,thanks for share information
Someday, my dreams will come true and I’ll wake up and Internet Explorer 28 will be out and finally standards compliant :)
Good tips, always have to include some minor adjustments to make my designs sing in IE6/7/8 … stupid IE, you would think that Microsoft with all the resources in the world would get their together… I think they’re just punishing the world by holding web standards back because they lost the ant-trust lawsuit…
This is NICE :-)
On our newly configured websites we used http://css3pie.com/ to make the CSS3 things work in IE. Works amazing and handy!
For all other basic IE stuff ofcourse you will need the tips above, thnx for this explanation!
obviously you didn’t test your hacks before you posted them.
\9 hits ALL versions of IE (including 9)
Having to use these hacks gives me a headache. At least Microsoft is now joining the campaign to end the abomination that is IE6: http://www.ie6countdown.com/
Very useful post. I agree with Jon. I hate to make special code ONLY for IE6 which is one of the worst browsers EVER! But either I like it or not, it needs to be done until this browser fades away completely (hopefully) I have been looking for a post that gives tips for IE6. I will share it in Facebook. Thanks
http://webdesignersbest.com/
online project auction for clients and web designers
also buy services on site. web design, graphics, etc.
This is really interesting! I’ll visit this site more often to learn new things about French. I love this site! I’ll recommend this to my friend!