有没有一种标准的方式可以在CSS中检测IE和Edge浏览器?我看到了检测javascript文件中的回复,但我正在寻找CSS中的一种方法。
有没有一种标准的方式可以在CSS中检测IE和Edge浏览器?我看到了检测javascript文件中的回复,但我正在寻找CSS中的一种方法。
对于IE 9及以下版本,请加载一个条件样式表:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->
IE10及以上版本不支持此功能,因此您需要使用媒体查询:
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS */
}
对于Edge 12-15版本:
@supports (-ms-accelerator:true) {
/* Edge 12+ CSS */
}
编辑
适用于 Edge 16+ 版本
@supports (-ms-ime-align:auto) {
/* Edge 16+ CSS */
}
Edge的被接受答案在Edge 16中无效。
这个替代方案可行:
@supports (-ms-ime-align:auto) {
/* IE Edge 16+ CSS */
}
不确定是否涉及Edge浏览器,但是如果要针对IE 10/11版本进行操作,可以使用以下代码:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
//styles
}
@supports (-ms-accelerator:true) or (-ms-ime-align:auto) {
// your css here
}
全能型:
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active),
@supports (-ms-accelerator:true) or (-ms-ime-align:auto) {
/* All CSS is here */
.example {
/* ... */
}
}
.example
,在 Internet Explorer 10/11 和 Edge 12+ 中应用所需的样式。 - Blarzek