I want to select a child element that does not contain a class that begins with z-depth-:
<div> <div></div>
</div>So that if the inner .well also contained a class like z-depth-1 it would not be selected.
This isn't working because the inner .well is always selected:
.well .well:not([class^="z-depth-"])Is that even possible?
32 Answers
You can't select a child element that does not contain a class that begins with z-depth- with CSS, you can only:
- Select all the child elements whose
classattribute's values don't start fromz-depth-substring:
.well .well:not([class^="z-depth-"]) { color: red;
}<div>Parent div <div>First child div</div> <div>Second child div</div>
</div>- Select all the child elements whose
classattribute's values don't containz-depth-substring:
.well .well:not([class*="z-depth-"]) { color: red;
}<div>Parent div <div>First child div</div> <div>Second child div</div> <div>Third child div</div>
</div>You also could read more about all CSS Selectors on MDN.
6You will need to combine ^= and *= to get the desired result.
.well:not([class^="z-depth-"]) { /*will ignore elements if the first class is z-depth-* */ background-color: lightgreen;
}
.well:not([class*=" z-depth-"]) { /*will ignore elements if z-depth-* is second class or later */ background-color: skyblue;
}<div>z-depth-1 well</div>
<div>well z-depth-1</div>Here's a nice guide on how to use attributes selectors.
1