The CSS selector :last-of-type
selects the last element of the type. Is there a way for me to select everything which comes before the last element of the type?
You can use :not(:last-of-type)
div span {
display: inline-block;
width: 20px;
height: 20px;
background: #000;
}
div span:not(:last-of-type) {
background: red;
}
<div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
I saw the :not operator in another answer and then tried this and it worked well. Not sure if there is a performance difference.
:nth-last-child(n+2)
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