IE specific CSS without hacking

You can customize your CSS for the many IE faults by using the conditional comments in your html document.

For example to include an additional CSS script containing all your IE hacks you would add the following after your main CSS include:

Show Plain Text
HTML code
  1. <!--[if IE]>
  2. <link rel="stylesheet" href="ie.css" type="text/css" />
  3. <![endif]-->

The conditional comments can be specific to a version of IE, for example <!--[if lt IE 7]> will target all versions of the IE browser less than 7. For further options refer to the MSDN page About Conditional Comments.

Why bother you say? My original motivation was to get W3C CSS compliance which does not take into account everyone needs to hack IE to get things displayed correctly. Having a separate CSS file also allows me to centralize my hacks for IE.

This may help with the hacks IE requires but doesn't help with other browsers hacks that might crop up, however since IE (for some unknown reason) is still the dominant browser it will have to do for the present time.

Filed under: Design  Tags: Css

0 Responses to “IE specific CSS without hacking”

Sorry, comments have been closed for this post.