Lets say I have a wrapper for some big UI element with class="wrapper"
.
The HTML would be like:
<div class="wrapper">
/ a lot of other elements
</div>
Now I need to select each of elements and I go like this:
.wrapper > .first_element_class{}
.wrapper > .second_element_class{}
...
Is there a way to select all wrappers children with one line? Something like this:
.wrapper{
.first_class{}
...
}
The :nth-child(n) selector matches every element that is the nth child of its parent. n can be a number, a keyword (odd or even), or a formula (like an + b). Tip: Look at the :nth-of-type() selector to select the element that is the nth child, of the same type (tag name), of its parent.
Use :not() with :last-child inside to select all children except last one.
The * selector selects all elements. The * selector can also select all elements inside another element (See "More Examples").
you can use the universal selector *
if you don't know which element/class you will have
Something like this:
.wrapper>* {
color: red
}
<div class="wrapper">
<div class="test">this is red</div>
<span>this is red</span>
<section>this is red</section>
</div>
You can use white space to match all descendants of an element.
.wrapper * {
color: black;
}
https://www.w3.org/TR/CSS21/selector.html#descendant-selectors
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