针对IE 10使用样式

2021-06-08819次阅读css

条件注释在IE 10中已失效。在某些情况下需要针对IE 10使用特定样式,不妨试试这种思路。

用JavaScript将用户代理添加到html元素中上:

var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);

IE 10 的用户代理字符串是:

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)

这将导致:

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

然后你可以设置如下样式:

html[data-useragent*='MSIE 10.0'] h1 {
  color: blue;
}

 

上一篇: Node模块路径导入解析策略  下一篇: css3列表中图片与文字悬浮效果  

针对IE 10使用样式相关文章