爲什麼下面的代碼無法正常工作?它應該隱藏所有不是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