Mohamed Ahmed Mohamed Ahmed - 6 months ago 18
HTML Question

How can I exclude last two child elements with CSS selector?

I want to draw

bottom-border
under some div elements inside their parent but except the last two, knowing that number of child element is changeable:

<div id="parent">
<div>
One
</div>
<div>
Two
</div>
<div>
Three
</div>
<div>
Four
</div>
</div>


Is it possible to select all child elements except the last two?

d.g d.g
Answer

In this case, something like

#parent > div:not(:nth-last-of-type(-n+2)) {
  border-bottom: 1px solid red;
}

JSFiddle