Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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

#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:

https://codepen.io/senff/pen/KdbzNo