I would like to select all input
that is not a child of a parent having the class no-material
I used this selector, main *:not(.no-material) input
, which, to me, should work and select the last 4 input
s, but it doesn't.
Is this not possible, or what am I missing here?
Note, I know this can be done by first select all, and then deselect some, though that is exactly what I want to avoid.
Stack snippet
main *:not(.no-material) input {
border: 1px solid red;
}
<main>
<div class="no-material">
<input name="no-1">
</div>
<div>
<label class="no-material">
<input name="no-2">
</label>
</div>
<div>
<label class="no-material">
<span>
<input name="no-3">
</span>
</label>
</div>
<div>
<label>
<span class="no-material">
<input name="no-4">
</span>
</label>
</div>
<div>
<input name="no-1">
</div>
<div>
<label>
<input name="no-2">
</label>
</div>
<div>
<label>
<span>
<input name="no-3">
</span>
</label>
</div>
<div>
<label>
<span>
<input name="no-4">
</span>
</label>
</div>
</main>
As a side note, when done like this it works just fine and select the first 4 input
's
main *.no-material input {
border: 1px solid blue;
}
Stack snippet
main *.no-material input {
border: 1px solid blue;
}
<main>
<div class="no-material">
<input name="no-1">
</div>
<div>
<label class="no-material">
<input name="no-2">
</label>
</div>
<div>
<label class="no-material">
<span>
<input name="no-3">
</span>
</label>
</div>
<div>
<label>
<span class="no-material">
<input name="no-4">
</span>
</label>
</div>
<div>
<input name="no-1">
</div>
<div>
<label>
<input name="no-2">
</label>
</div>
<div>
<label>
<span>
<input name="no-3">
</span>
</label>
</div>
<div>
<label>
<span>
<input name="no-4">
</span>
</label>
</div>
</main>
I also want to give credit to this post from where I got the main code sample, though they seek a solution for Javascript and querySelectorAll()
, and I hoped for a CSS rule (or two :)