如何为IE设置特殊的CSS?

Mar*_*cel 6 html css internet-explorer

我想为ie8使用一些不同的CSS,但只保留一个CSS文件.谁能告诉我这个最好的"黑客"是什么?是的,我知道黑客不好,但我想保留一个CSS文件,至少目前.

例如,在非IE8浏览器中,我希望浏览器看到这个:

div.content_header_heading { 
    background: -moz-linear-gradient(top, #cccccc 0%, #eeeeee 35%, #eeeeee 65%, #cccccc 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cccccc), color-stop(35%,#eeeeee), color-stop(65%,#eeeeee), color-stop(100%,#cccccc)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #cccccc 0%,#eeeeee 35%,#eeeeee 65%,#cccccc 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #cccccc 0%,#eeeeee 35%,#eeeeee 65%,#cccccc 100%); /* Opera11.10+ */
    background: -ms-linear-gradient(top, #cccccc 0%,#eeeeee 35%,#eeeeee 65%,#cccccc 100%); /* IE10+ */
}
Run Code Online (Sandbox Code Playgroud)

但如果浏览器是IE8,我希望浏览器看到这个:

div.content_header_heading { 
}
Run Code Online (Sandbox Code Playgroud)

And*_*y E 19

Paul Irish对这个问题有很好的解决方案.它涉及使用条件注释在<html>标记上放置类:

<!--[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 class=""> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

然后你可以使用CSS规则来定位IE版本:

.ie8 div.content_header_heading { 
}
Run Code Online (Sandbox Code Playgroud)

http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/.