条件CSS的Internet Explorer 10只[复制](Conditional CSS fo

2019-07-22 09:38发布

这个问题已经在这里有一个答案:

  • 我怎么只针对Internet Explorer的10,如Internet Explorer特定CSS或Internet Explorer的特定的JavaScript代码的某些情况呢? 25个回答

Internet Explorer的10打破了我的jQuery的菜单。 我可以按照下面的例子将一个小改版,以我们的CSS解决这个问题。

/* For Internet Explorer 10 ------*/
margin-top: 1px;

/* For all other browsers ------*/
margin-top: 2px;

有没有条件申请这些情况在我的CSS包括的方法吗?

我知道浏览器嗅探并不理想,但这似乎很好地工作:

if ($.browser.msie  && parseInt($.browser.version, 10) === 10) {
    $(".jMenu li ul").css("margin", "1px");
}

Answer 1:

看到如你已经依靠JavaScript来你的菜单,你可以一类添加到<body>使用基于字符串的userAgent JavaScript代码:

JavaScript的

if (navigator.userAgent.indexOf("MSIE 10") > -1) {
    document.body.classList.add("ie10");
}

..和然后瞄准的Internet Explorer 10的CSS

CSS

/*IE 10 only */
.ie10 .myClass {
    margin-top: 1px;
}


文章来源: Conditional CSS for Internet Explorer 10 only [duplicate]