-
Both of the
span
elements’ parentdiv
elements don’t have the classno
, regardless of whether any other ancestors do have it or not:<div> <!-- This is div:not(.no), pretty much a given --> <span>yes 1</span> </div>
<div class="no"> <!-- In this case, although this is div.no... --> <div> <!-- ... this is div:not(.no)! --> <span>no 2</span> </div> </div>
-
Both
html
andbody
, which are ancestors of yourdiv
andspan
elements, satisfy*:not(.no)
when using a universal selector (or rather, when omitting a type selector). This causes all of yourspan
elements to have the background color.
One solution to this is to anchor your negation filter to the body
element using the child combinator, if your top-level div
elements will always be children of body
:
body > div:not(.no) span { background-color: #00f; }
Another solution is to simply use override styles.