In the following example, I’ll expect all p
elements to render with a green background, since the red background should only be apply if the .red
class is not a descendant of a .green
class. Yet, this is not the case.
.green p {
background: green;
}
:not(.green) .red > p {
background: red;
}
<section class="green">
<p>Neutrum vero, inquit ille. Et nemo nimium beatus est; Age, inquies, ista parva sunt. Haec para/doca illi..
<p/>
<div class="red">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Hoc enim constituto in philosophia constituta sunt omnia. Num quid tale Democritus..</p>
<p>Zenonis est, inquam, hoc Stoici. Certe, nisi voluptatem tanti aestimaretis. Erat enim Polemonis. Tanta vis admonitionis inest in locis.</p>
<p>Age sane, inquam. Omnis enim est natura diligens sui. Duo Reges: constructio interrete. Quid ergo attinet gloriose loqui.</p>
</div>
<p>Pro consul accusata id, errem nonumy assentior qui et. Quem albucius omittantur id sea, duo cu posse insolens.
<p/>
</section>
Why the negation selector is not working as expected in this example?
`s will have a green background.
– KevSlashNull Mar 15 '20 at 14:54