.parent .child:last-child {
color: red;
}
<div class="parent">
<div class="child">
text
<div class="child">
text
<div class="child">text</div>
</div>
</div>
</div>
I would only like the text of the last nested child to have a font-color of red. is this acheivable with CSS only?
2
Answers
You can use the
:not()
selector in combination with:has()
to dynamically target the innermost.child
div:the selector would something like a div with class child that has not a child with class child :
.child:not(:has(.child))