Working Ninja
2019-02-27T21:06:20
Get Second to Last Element via CSS

Take the following HTML snippet:

<ul>
    <li></li>
    <li></li>
    <li></li>
    <li>Second to Last</li>
    <li></li>
</ul>

We would like to select the second to last list item (<li>). Here's how we'd go about doing that:

ul li:nth-last-child(2) { color: blue; }

Or, the inverse (everything but the second to last element):

ul li:not(:nth-last-child(2)) { color: red; }