Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

IE7 and the demise of CSS hacks

As mentioned previously here and elsewhere, Microsoft is working on Internet Explorer 7, which will have greatly improved CSS support. The IE7 team has posted an article about the demise of CSS hacks and broken pages, warning that the hacks often used to target CSS specifically to work around old IE bugs may be unnecessary under IE7 when in strict mode. So, IE will finally have improved support for standards, but all of our old hacks could cause breakage in the new browser. As Monk would say, “it’s a blessing and a curse.”

The recommended workaround is to use IE’s conditional comments feature to load a stylesheet with rules specifically for IE6 and older. For example you might put something like this in the <head> of your document:

<link rel="stylesheet" type="text/css" href="compliant.css" />
<!--[if IE lt 7]>
<link rel="stylesheet" type="text/css" href="ie-rules.css" />

This would load the compliant.css file for all browsers. Then, the conditional comment would load the ie-rules.css file only for Internet Explorer with a version less than 7. All other browsers (including IE7) would ignore this comment. [Note, however, that this hack doesn’t apply to the specific Slashdot example used in the IEBlog article. Read the comments to see why.]

Note that this only applies if you are using IE-specific hacks in standards-compliance mode. This includes hacks which target rules to only work in IE (like my favorite, the star html hack), or rules that only work in compliant browsers (like the child selector hack). And it may not be necessary in all cases anyhow, depending on how you are using those rules (the main problem is probably going to be that the star html hack won’t work in IE7 even in quirks mode). Theoretically, if you are using quirks mode, then you can probably just continue using your old hacks. However, I think most of us would probably prefer to keep to the standards whenever possible.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in Browsers, CSS, Design, Standards and tagged , , , . Bookmark the permalink.

18 Responses to IE7 and the demise of CSS hacks

  1. Pingback: Techniek » IE 7 en CSS hacks

  2. Pingback: Web Standards Project BUZZ

  3. Pingback: Syntetica CTRL+C » Blog Archive » Pandora’s Box (Model) of CSS Hacks And Other Good Intentions

Leave a Reply

%d bloggers like this: