Using the last-child selector

Miral picture Miral · Aug 18, 2009 · Viewed 187k times · Source

My goal is to apply the CSS on the last li, but it doesn't do that.

How can I select only the last child?

Answer

VoteyDisciple picture VoteyDisciple · Aug 18, 2009

The :last-child pseudoclass still cannot be reliably used across browsers. In particular, Internet Explorer versions < 9, and Safari < 3.2 definitely don't support it, although Internet Explorer 7 and Safari 3.2 do support :first-child, curiously.

Your best bet is to explicitly add a last-child (or similar) class to that item, and apply li.last-child instead.