Home › Forums › CSS › Styling li except when a parent div has specific class › Reply To: Styling li except when a parent div has specific class
November 12, 2015 at 8:19 am
#234856
Senff
Participant
Yeah, the issue is that you can’t really rely on the :not one, because something like div:not(.a) li
would only work if the LI is not within another div.
I think specificity is the issue here. Let’s say when you have this:
li {background:red;}
div:not(.a) li {background:green;}
Then the LI will still be green if it’s within a nested DIV (with a class that’s not “a”), even when a parent DIV (or grandparent, or….) has class “a”.
So I guess you’re gonna have to use some JS. Something like this: