The tool of choice for fighting IE problems is the conditional stylesheet
. IE provides comment tags, supported all the way up to the current IE 8 to target specific versions, as well as greater-than/less-than stuff for targeting multiple versions at once.
Why use conditional stylesheets?
- You got problems, they need fixin’
- Keeps your code hack-free and valid
- Keeps your main stylesheet clean
- Perfectly acceptable technique, sanctioned by Microsoft
And remember, these conditional tags don’t have to be used only for CSS. You could load JavaScript, or even use them down in the content of your site to display special IE-specific messages.
The Code
This would go in your
with all the other regular CSS <link>ed CSS files. The opening and closing tags should be familiar, that’s just regular ol’ HTML comments. Then between the brackets, “IF” and “IE” should be fairly obvious. The syntax to note is “!” stand for “not”, so !IE means “not IE”. gt means “greater than”, gte means “greater than or equal”, lt means “less than”, lte means “less than or equal.”Note that IE 10 and up DO NOT support conditional comments at all.
Target ALL VERSIONS of IE
1 | <!--[if IE]> |
Target everything EXCEPT IE
1 | <!--[if !IE]><!--> |
Target IE 7 ONLY
1 | <!--[if IE 7]> |
Target IE 6 ONLY
1 | <!--[if IE 6]> |
Target IE 5 ONLY
1 | <!--[if IE 5]> |
Target IE 5.5 ONLY
1 | <!--[if IE 5.5000]> |
Target IE 6 and LOWER
1 | <!--[if lt IE 7]> |
Target IE 7 and LOWER
1 | <!--[if lt IE 8]> |
Target IE 8 and LOWER
1 | <!--[if lt IE 9]> |
Target IE 6 and HIGHER
1 | <!--[if gt IE 5.5]> |
Target IE 7 and HIGHER
1 | <!--[if gt IE 6]> |
Target IE 8 and HIGHER
1 | <!--[if gt IE 7]> |
Note: The original artical you can see here