如何在样式表中只定位IE(​​任何版本)?

我有一个inheritance的项目,有些地方是一片混乱。 这是其中之一。 我只需要瞄准IE(任何版本)。

#nav li { float: left; height: 54px; background: #4f5151; display: table; border-left: 1px solid grey; } 

要清楚的是: embedded式样式表中,并且没有向html中的标签添加ID或类, 只有在用户使用IE 时才需要应用边框样式。 我怎样才能做到这一点?

编辑:find一个Firefox的解决scheme,编辑问题来反映这一点。

Internet Explorer 9及更低版本:您可以使用条件注释为任何想要专门定位的版本(或其组合版本)加载特定于IE的样式表。您可以使用外部样式表。

 <!--[if IE]> <link rel="stylesheet" type="text/css" href="all-ie-only.css" /> <![endif]--> 

但是,从版本10开始,IE中不再支持条件注释。

Internet Explorer 10和11:使用-ms-high-contrast创build媒体查询,在其中放置您的IE 10和11特定的CSS样式。 因为-ms-高对比度是特定于Microsoft的(仅适用于IE 10+),所以只能在Internet Explorer 10及更高版本中进行parsing。

 @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { /* IE10+ CSS styles go here */ } 

Microsoft Edge 12:可以使用@supports规则以下是有关此规则的所有信息的链接

 @supports (-ms-accelerator:true) { /* IE Edge 12+ CSS styles go here */ } 

内联规则IE8检测

我有1个更多的选项,但它只是检测IE8及以下版本。

  /* For IE css hack */ margin-top: 10px\9 /* apply to all ie from 8 and below */ *margin-top:10px; /* apply to ie 7 and below */ _margin-top:10px; /* apply to ie 6 and below */ 

当你满足embedded式样式表。 我认为你需要使用下面的版本的媒体查询和条件评论。

使用SASS我使用以下2 @media queries来定位IE 6-10和EDGE。

 @media screen\9 @import ie_styles @media screen\0 @import ie_styles 

http://keithclark.co.uk/articles/moving-ie-specific-css-into-media-blocks/

编辑

我还使用@support queries定位更高版本的EDGE(根据需要添加尽可能多的)

 @supports (-ms-ime-align:auto) @import ie_styles @supports (-ms-accelerator:auto) @import ie_styles 

https://jeffclayton.wordpress.com/2015/04/07/css-hacks-for-windows-10-and-spartan-browser-preview/

另一个针对IE特定样式的工作解决scheme是

 <html data-useragent="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"> 

然后你的select器

 html[data-useragent*='MSIE 10.0'] body .my-class{ margin-left: -0.4em; }