I am trying to make the PINK color only apply up to the 7 div element that contains the children class, I had thought of a :nth-child but I have not been able to implement it
.padre .children {
width: 200px;
height: auto;
border: 1px solid;
margin-bottom: 10px;
padding: 10px;
background-color: red;
}
.padre .children *.children:last-of-type {
background-color: pink;
}
<div class="padre">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children">
<div class="children"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Turning the reasoning around a bit, what you can do is make all the elements
.children
pink and create a specific rule so that from the eighth they turn red.To do this, you can use the selector
>
to refer to the direct descendant until you reach the descendants of the seventh.children
.Taking into account answer number 2, you could avoid the .children by placing
Do you have possibility to add an additional class to the elements that you don't want PINK to be applied to? You could do the following:
Adding the "no" class to divs you don't want to paint.