如何仅定位样式表中的IE(任何版本)? [英] How to target only IE (any version) within a stylesheet?
问题描述
我有一个继承的项目,有一些地方,它是一个彻底的混乱。这是其中之一。我需要只定位IE(任何版本)。
#nav li {
float:left;
height:54px;
background:#4f5151;
display:table;
border-left:1px solid gray;
}
要清楚: 不需要在html中的标签中添加ID或类,如果用户正在使用IE,则只需要应用边框样式 。我如何做到这一点?
编辑:找到了Firefox的解决方案,编辑问题以反映这一点。
Internet Explorer 9及更低版本:
您可以使用条件注释来为您要专门定位的任何版本(或组合版本)加载特定于IE的样式表。
<! - [if IE]>
< link rel =stylesheettype =text / csshref =all-ie-only.css/>
<![endif] - >
但是,从版本10开始,IE中不再支持条件注释。
Internet Explorer 10& 11:
使用-ms-high-contrast创建媒体查询,在其中放置IE 10和11特定的CSS样式。因为-ms-high-contrast是Microsoft特定的(仅在IE 10+中可用),所以它只会在Internet Explorer 10及更高版本中解析。
@media all和(-ms-high-contrast:none),(-ms-high-contrast:active){
/ * IE10 + CSS样式到这里* /
}
Microsoft Edge 12:可以使用@supports规则
以下是包含此规则的所有信息的链接
@supports(-ms-accelerator:true){
/ * IE Edge 12+ CSS样式到这里* /
}
内联规则IE8检测
我还有1个选项,但它只检测IE8及以下版本。
/ *对于IE css hack * /
margin-top:10px \9 / *适用于所有ie从8及以下* /
* margin-top:10px; / * apply to ie 7 and below * /
_margin-top:10px; / *适用于ie和以下* /
正如您嵌入的样式表所述。我认为你需要使用媒体查询和条件评论为以下版本。
I have an inherited project and there are places where it's an utter mess. This is one of them. I need to target only IE (any version).
#nav li {
float: left;
height: 54px;
background: #4f5151;
display: table;
border-left: 1px solid grey;
}
To be clear: Inside the embedded stylesheet and without adding ID's or classes to the tags in the html, I need to apply the border style only if the user is using IE. How can I do this?
Edit: found a solution for Firefox, editing question to reflect this.
Internet Explorer 9 and lower : You could use conditional comments to load an IE-specific stylesheet for any version (or combination of versions) that you wanted to specifically target.like below using external stylesheet.
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
However, beginning in version 10, conditional comments are no longer supported in IE.
Internet Explorer 10 & 11 : Create a media query using -ms-high-contrast, in which you place your IE 10 and 11-specific CSS styles. Because -ms-high-contrast is Microsoft-specific (and only available in IE 10+), it will only be parsed in Internet Explorer 10 and greater.
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}
Microsoft Edge 12 : Can use the @supports rule Here is a link with all the info about this rule
@supports (-ms-accelerator:true) {
/* IE Edge 12+ CSS styles go here */
}
Inline rule IE8 detection
I have 1 more option but it is only detect IE8 and below version.
/* 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 */
As you specefied for embeded stylesheet. I think you need to use media query and condition comment for below version.
这篇关于如何仅定位样式表中的IE(任何版本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!