Here is the html layout
<div class="wrap">
<div class="section">
<span class="text">text1</span>
</div>
<span class="text">text2</span>
<span class="not-text">don't color me!</span>
</div>
Im trying to give a style to all "text" spans which are not in the "section" divs.
I tried this, but it doesn’t seem to be working
.wrap :not(.section) .text
Any help is greatly appreciated!
Edit: There are several workarounds for this case including the use of > operator like in ".wrap > .text", but I would like to know how to make the :not selector working, to make use of it in the future
When you use
.wrap :not(.section) .text, this is what you’re telling the browser:.text.sectionan element that has a class of
.wrapIf you look closely at your markup, none of your elements meet that selector criteria.
In the markup you provided, I don’t think you can specifically select those
.textelements that are not descendants of.sectionusing:not().The closest you could get is by using a direct descendant selector, like this:
You could also select and style all
.textdescendants of.wrap(whether direct or not), and then cancel those styles for any.textelements inside of.section, like this: