22

只是想知道我的技巧包中有这些 IE hack

"\9" - for IE8 and below.
"*" - for IE7 and below.
"_" - for IE6.

即如

body { 
    border:2px solid blue;
    border:2px solid yellow \9;
    *border:2px solid green;
    _border:2px solid orange;
}

是否有人对 IE9 有这样的 hack?即我试图仅通过 CSS 定位 IE9 吗?

4

5 回答 5

42

可怕,但它应该工作:

body { 
    border:2px solid blue;
    border:2px solid yellow \9;
    *border:2px solid green;
    _border:2px solid orange;
}
body:nth-child(n) {border:1px solid purple \9; /*Should target IE9 only - not fully tested.*/}
于 2012-03-23T20:36:29.807 回答
29

我建议使用condcoms来提供 IE9 css 文件或有条件的 html 类,类似于:

<!--[if lt IE 7]> <html lang="en-us" class="no-js ie6"> <![endif]--> 
<!--[if IE 7]>    <html lang="en-us" class="no-js ie7"> <![endif]--> 
<!--[if IE 8]>    <html lang="en-us" class="no-js ie8"> <![endif]--> 
<!--[if gt IE 8]><!--> <html lang="en-us" class="no-js"> <!--<![endif]--> 
于 2011-07-11T18:06:23.137 回答
4

IE9 非常符合标准。你不应该破解它。

此外,您应该使用IE 条件注释来加载不同的样式。对于 IE 9,你会这样做:

<!--[if IE 9]>
    <!-- conditional content goes here -->
<![endif]-->
于 2011-07-11T18:07:11.740 回答
4

在这个地址:http ://www.impressivewebs.com/ie10-css-hacks/ 我发现了一个仅针对 IE10(及以下)的媒体查询:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {  
   /* IE10-specific styles go here */  
}
于 2013-05-28T16:00:20.243 回答
3

正如一些评论中所指出的,有时条件 HTML 不适用于特定情况,尤其是在您无法修改页面代码本身的情况下。所以这里有一个解决方法:

基本风格

.test{color:red;}

特定于浏览器的覆盖

IE < 8:html >/**/body .test { color: green; }
IE 9::root .test{color:green \ ;}
IE 8 和 9:.test{color:green \ ;}
IE 9 和 Opera:root .test {color: green\0;}

笔记

以上不适用于backgroundor font-*,并且任何\0or\9黑客通常都是不稳定的。有关 CSS hack 的完整列表,请参阅http://mynthon.net/howto/-/webdev/CSS-big-list-of-css-hacks.txt

于 2015-09-23T21:00:59.183 回答