Html 我怎样才能有IE的特殊CSS?

Html 我怎样才能有IE的特殊CSS?,html,css,internet-explorer,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+ */ b

我想为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+ */
}
div.content_header_heading { 
}
但如果浏览器是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+ */
}
div.content_header_heading { 
}
对这个问题有很好的解决办法。它涉及使用条件注释将类放置在
标记上:


然后,您可以使用CSS规则将IE版本作为目标:

.ie8 div.content\u header\u heading{
}

请参阅。

我遇到的最好方法是为Internet Explorer使用不同的CSS文件

然后在HTML中,您可以使用在internet上找到的典型条件代码块排除或包含它们

<!--[if IE 6]>
  CSS HERE
<![endif]-->

只输入那些在IE版本中需要不同的CSS行。

确保浏览器解释每个html元素的最好方法是使用


如果您想使用页眉、页脚或其他新的html5元素,Modernizer将创建它们,以便旧浏览器能够理解这些元素。

IE上不同版本的CSS最简单的方法是:

.color {color: #777;} /* for all browsers */
* html .color {color: #C39;} /* for IE6 */
*+html .color {color: #66F;} /* for IE7 (you can also use the long expresion " *:first-child+html ") */
.color {color: #0FC\0/;} /* for IE8, going last */

以上所有内容都是黑客攻击,但至少他们使用了有效的CSS,除了IE8的黑客攻击,我建议使用条件注释。

这可能的重复看起来非常好。任何人都知道如何将此与其他代码结合起来:顺便问一下,这是什么代码?我不熟悉用这种方式使用代码。我想补充一点,你可以不使用类,而使用整个CSS文件只是为了特定的IE。想法是一样的,但你不会弄乱你的普通CSS文件。我只有一个地方,我希望CSS是不同的,所以使用另一个文件是有点过分。Thanks@Maricel:这些是“条件注释”,这是一项仅适用于IE的功能,允许您使用HTML注释将标记指向特定版本的IE或非IE浏览器。没有
else
语句,因此您无法将它们组合到单个条件注释中。