Codepen example is here.
Question. How do I paint yellow all inputs that are NOT descendants of div.b
?
My attempt paints all three elements yellow:
:not(.b) input.myInp {background:yellow}
Thanks!
Codepen example is here.
Question. How do I paint yellow all inputs that are NOT descendants of div.b
?
My attempt paints all three elements yellow:
:not(.b) input.myInp {background:yellow}
Thanks!
:not(.b) > div > p input.myInp {background:yellow}
You need to make the selector specific enough that it does not match with the parent .a element.
Your selector is not working because you're targeting any element that does not have the class .b
but has an <input>
descendant, and since the input has two ancestor elements which don't have this class the rule applies to them as well.
You should just specify that you're referring to the container's themselves by including the parent in your selector:
div.a > :not(.b) input.myInp {background:yellow}