Reputation: 171341
Consider the following HTML:
<div class="a">
<div class="b">Hello</div>
</div>
<div class="c">
<div class="b">World</div>
</div>
Adding the following CSS colors only "World" in red, as expected:
.c .b {
color: red;
}
But, adding the following CSS instead colors both "Hello" and "World" in red:
:not(.a) .b {
color: red;
}
Why?
Upvotes: 3
Views: 3663
Reputation: 20862
Since the :not
pseudo-class represents an element that is not represented by its argument,
you have to specify the element you want to exclude before the :not
selector
Per your example, try this instead:
div:not(.a) .b {
color: red;
}
Upvotes: 3
Reputation: 123739
You need to give it like this:-
div:not(.a) .b {
color: red;
}
Syntax is selector:not(){ properties }
Upvotes: 7