Conditional CSS for Internet Explorer 10 only(仅适用于 Internet Explorer 10 的条件 CSS)
问题描述
Internet Explorer 10 破坏了我的 jQuery 菜单.我可以按照下面的示例对我们的 CSS 进行小修改来解决此问题.
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;
有没有办法在我的 CSS 包含中有条件地应用这些情况?
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");
}
推荐答案
既然你的菜单已经依赖 JavaScript,你可以使用 JavaScript 向 <body>
添加一个类基于userAgent字符串的代码:
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:
if (navigator.userAgent.indexOf("MSIE 10") > -1) {
document.body.classList.add("ie10");
}
..然后在您的 CSS 中定位 Internet Explorer 10
..and then target Internet Explorer 10 in your CSS
/*IE 10 only */
.ie10 .myClass {
margin-top: 1px;
}
这篇关于仅适用于 Internet Explorer 10 的条件 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:仅适用于 Internet Explorer 10 的条件 CSS


基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01