html - ie9 中的 'not' css 选择器

标签 html css internet-explorer-9

根据 http://www.w3schools.com/cssref/sel_not.asp IE9 支持“not”选择器 但是,以下内容在 ie9 中不起作用:

HTML:

<input type="checkbox"><span>I agree to the terms and conditions</span>

CSS:

input:not(:checked) + span
{
    font-weight:bold;
    text-decoration:underline;
    color:red;
}

当您选中该复选框时,样式仍会应用。在其他浏览器(FF、Chrome)中,它按预期工作。

这是 IE9 的某种错误吗?

谢谢。

最佳答案

我不知道这个错误到底是什么,但我有一个解决方法。

通过一些实验我发现如果你把这条线

input:checked + p {}

在您的 CSS 之上,您的 CSS 在 IE 中运行良好。所以我建议你把它放进去然后忘记它,除非你想投入大量时间来找出错误的确切程度。

input:checked + p {}

input:not(:checked) + span {
  font-weight: bold;
  text-decoration: underline;
  color: red;
}
<input type="checkbox"><span>I agree to the terms and conditions</span>

为了测试,您可以注释掉第一行,然后它在 IE 中停止工作。

关于html - ie9 中的 'not' css 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934107/

相关文章:

html - 如何让我的 <li> 在我的导航中居中

css - Angular:单元格的 innerHtml 中的 CSS 类用法

javascript - 当在 div 中检测到垂直溢出时,有没有办法触发事件?

html - Internet Explorer 在使用内联 block 悬停 anchor 时增长 div

jquery - 使用 jquery ui slider 更改 css

html - 使用 HtmlAgilityPack 将 HTML 转换为字符串

javascript - 如何使用 $scope 和 ng-bind 检索 AngularJS 中的文本框条目

html - 容器内的 Div 似乎不在页面中心

jquery - 为什么 IE9 不以兼容模式从我的 Intranet 服务器运行 javascript?