定位到IE9或IE8,但不要同时使用CSS

|| 我知道不应该这样做,但是我现在只想要一个快速修复,这将使我有时间找到适当的修复方法。 我如何使用CSS单独定位IE8,因为我尝试附加“ 0”,例如:
margin:100px\\9;
但是,它也影响IE9,我不希望这样做,因为在IE9上,整个网站看起来都不错。     
已邀请:
来自HTML5 Boilerplate,最初来自Paul Irish: 将您的标记更改为此:
<!--[if lt IE 7 ]> <html lang=\"en\" class=\"ie6\"> <![endif]-->
<!--[if IE 7 ]>    <html lang=\"en\" class=\"ie7\"> <![endif]-->
<!--[if IE 8 ]>    <html lang=\"en\" class=\"ie8\"> <![endif]-->
<!--[if IE 9 ]>    <html lang=\"en\" class=\"ie9\"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang=\"en\"> <!--<![endif]-->
然后IE8将.ie8类添加到html标记中。所有其他版本的IE相同。然后,您可以执行以下操作:
.ie8 {
    margin:100px;
}
编辑:删除了no-js类,请更新lang = \“ \”属性为您的语言。谢谢,失明。     
这应该仅在IE9(以及可能是较新的版本)中起作用:
:root #element-id {
  margin: 400px\\9;
}
这是因为在IE9之前的版本中未实现“ 5”伪类(请参见http://msdn.microsoft.com/zh-cn/library/cc351024%28v=vs.85%29.aspx)。     
您可以使用根函数
:root #element { color:pink \\0/IE9; } /* IE9 + IE10pp4 */
仅在IE上破解
#element {
color:orange;
}
#element {
*color: white;    /* IE6 + 7, doesn\'t work in IE8/9 as IE7 */
}
#element {
_color: red;     /* IE6 */
}
#element {
color: green\\0/IE8+9; /* IE8 + 9 + IE10pp4  */
}
:root #element { color:pink \\0/IE9; }  /* IE9 + IE10pp4 */
    
有三种方法可以做到这一点, IE条件注释 IE条件注释可能是修复特定版本(IE6,IE7,IE8)的IE错误最常用的方法。下面是一些针对不同版本的Internet Explorer的示例代码:
    <!--[if IE 8]> = IE8
    <!--[if lt IE 8]> = IE7 or below
    <!--[if gte IE 8]> = greater than or equal to IE8
<!--[if IE 8]>
<style type=\"text/css\">
    /* css for IE 8 */
</style>
<![endif]-->

<!--[if lt IE 8]>
    <link href=\"ie7.css\" rel=\"stylesheet\" type=\"text/css\" />
<![endif]-->
特定于Explorer的CSS规则(IE CSS hacks) 另一个选择是声明只能由Explorer读取的CSS规则。例如,在CSS属性针对IE7之前添加一个星号(*),或者在该属性针对IE6之前添加一个下划线。但是,不建议使用此方法,因为它们不是有效的CSS语法。
IE8 or below: to write CSS rules specificially to IE8 or below, add a backslash and 9 (\\9) at the end before the semicolon.
IE7 or below: add an asterisk (*) before the CSS property.
IE6: add an underscore (_) before the property.

.box {

    background: gray; /* standard */

    background: pink\\9; /* IE 8 and below */

    *background: green; /* IE 7 and below */

    _background: blue; /* IE 6 */

}
条件HTML类 由Paul Irish创建的第三个选项是,通过使用IE条件注释,将带有IE版本的CSS类添加到HTML标记中。基本上,它会检查它是否是IE,然后将一个类添加到html标记中。因此,要针对特定​​的IE版本,只需使用IE类作为父选择器(例如.ie6 .box)。这是一种聪明的方法,不会引起任何验证错误。
<!--[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> <!--<![endif]-->
    

要回复问题请先登录注册