css - 这两个使用 “:not” 的选择器有什么区别?

标签 css css-selectors

这两个选择器有什么区别?

input:not([type="radio"][type="submit"])
input:not([type="radio"]):not([type="submit"])

请问 <input>没有 type 的标签选择属性?

我读过:

最佳答案

引用 the Selector Level 4 docs :

The negation pseudo-class, :not(), is a functional pseudo-class taking a selector list as an argument. It represents an element that is not represented by its argument.

Note: In Selectors Level 3, only a single simple selector was allowed as the argument to :not().

这就解释了为什么这......

input:not([type="radio"][type="submit"])

... 在任何不实现这部分 CSS4 规范的浏览器中都不支持(据我所知,目前还没有人这样做;毕竟它只是一个工作草案)。但是这个选择器的逻辑也有缺陷:即使语法得到普遍支持,它也应该写成...

input:not([type="radio"],[type="submit"])

请参阅,[foo][bar] 规则被视为要求任何元素都 foobar。但是(当然!)任何输入都不可能同时是 radiosubmit 类型。

底线:你必须使用...

input:not([type="radio"]):not([type="submit"])

...因为CSS3 only supports simple selectors:not.

关于css - 这两个使用 “:not” 的选择器有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33012862/

相关文章:

javascript - 使页面剥离效果更好

javascript - Rails、JS、CSS - 无法获得过渡效果

html - 仅当其父级不是 <pre> 时,我如何设置 <code> 样式?

css - :where() and :is()?有什么区别

css - 是:before pseudo-element allowed on an input[type=checkbox]?

css - 以编程方式设置 CSS 选择器特异性

html - Angular2 + Kendo MultiSelect 每行列出每个元素

html - 段落不使用左边距移动

javascript - 我必须添加什么才能使这个 Accordion UI 模块在 Meteor 中工作?

python - 如何通过css选择器选择标签