且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在CSS中检测IE和Edge浏览器?

更新时间:2022-03-05 09:34:02

对于IE 9及更低版本,请加载条件样式表:

For IE 9 and lower, load a conditional stylesheet:

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

IE 10及更高版本不支持此功能,因此您必须使用媒体查询:

IE 10 and up doesn't support this, so you have to use media queries:

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

对于Edge 12-15:

For Edge 12-15:

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

编辑

对于Edge 16 +

For Edge 16+

@supports (-ms-ime-align:auto) {
    /* Edge 16+ CSS */ 
}