为什么下面的代码无法正常工作?它应该隐藏所有不是p
的元素,但display
属性无法正常工作。:无(选择器)无法正常工作
p {
color: #000000;
}
:not(p) {
display: none;
color: #ff0000;
}
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<div>This is some text in a div element.</div>
<a href="http://www.w3schools.com" target="_blank">Link to W3Schools!</a>
您必须指定:body:not(p) – Laurianti
按预期工作。隐藏除“p”之外的所有元素,包括“p”的祖先。 – Oriol
@Oriol代码具有正确的行为,但不是OP正在寻找的;) – dippas