仅限Internet Explorer 10的条件CSS [英] Conditional CSS for Internet Explorer 10 only
本文介绍了仅限Internet Explorer 10的条件CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Internet Explorer 10已损坏了我的jQuery菜单。
/ *对于Internet Explorer 10,我们可以通过对我们的CSS应用一个小的修订来解决这个问题。 ---- * /
margin-top:1px;
/ *对于所有其他浏览器------ * /
margin-top:2px;有没有办法有条件地应用这些情况在我的CSS包括?
b
我知道浏览器嗅探并不理想,但这似乎很好:
if .browser.msie&& parseInt($。browser.version,10)=== 10){
$(。jMenu li ul)。css(margin,1px);
}
解决方案您可以使用基于userAgent字符串的JavaScript代码向< body>
添加类:
JavaScript
if(navigator.userAgent.indexOf(MSIE 10)> -1){
document.body.classList.add(ie10);
}
..然后在您的CSS中将Internet >
CSS
/ * IE 10 only * /
.ie10 .myClass {
margin-top:1px;
}
Internet Explorer 10 has broken my jQuery menu. I can fix this by applying a small revision to our CSS as per the example below.
/* For Internet Explorer 10 ------*/
margin-top: 1px;
/* For all other browsers ------*/
margin-top: 2px;
Is there a way to apply these cases conditionally in my CSS include?
I know browser sniffing is not ideal, but this seems to work fine:
if ($.browser.msie && parseInt($.browser.version, 10) === 10) {
$(".jMenu li ul").css("margin", "1px");
}
解决方案 Seeing as you're already relying on JavaScript for your menu, you could add a class to the <body>
using JavaScript code based on the userAgent string:
JavaScript
if (navigator.userAgent.indexOf("MSIE 10") > -1) {
document.body.classList.add("ie10");
}
..and then target Internet Explorer 10 in your CSS
CSS
/*IE 10 only */
.ie10 .myClass {
margin-top: 1px;
}
这篇关于仅限Internet Explorer 10的条件CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文