WP-Mix

A fresh mix of code snippets and tutorials

CSS select all except last child

Blazing fast snippet for you today: how to select all children except the last child. Targeting HTML with CSS has never been so much fun..

.target:not(:last-child) {
	/* do your thing */
	}

So if .target is a list:

<ul class="target">
	<li>Item 1</li>
	<li>Item 2</li>
	<li>Item 3</li>
</ul>

..then the previous CSS selector will select the first two items in the list, but not the last item. That’s all there is to it.. gotta love the power of CSS :)

★ Pro Tip:

Digging Into WordPress