I want to select a child element that does not contain a class that begins with z-depth-
:
<div class="well">
<div class="well"></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?
In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.
To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)
To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.
The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
You can't select a child element that does not contain a class that begins with z-depth-
with CSS, you can only:
class
attribute's values don't start from z-depth-
substring:.well .well:not([class^="z-depth-"]) {
color: red;
}
<div class="well z-depth-1">Parent div
<div class="z-depth-2 well">First child div</div>
<div class="well z-depth-3">Second child div</div>
</div>
class
attribute's values don't contain z-depth-
substring:.well .well:not([class*="z-depth-"]) {
color: red;
}
<div class="well z-depth-1">Parent div
<div class="z-depth-2 well">First child div</div>
<div class="well z-depth-3">Second child div</div>
<div class="well">Third child div</div>
</div>
You also could read more about all CSS Selectors on MDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With