O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

:nth-last-child(an+b)

Applies to:

Any element

Description:

Matches every nth child with the pattern of selection defined by the formula an+b, where a and b are <integer>s and n represents an infinite series of integers, counting backward from the last child. Thus, to select every fourth-to-last child of the body element, starting with the last child, you write body > *:nth-last-child(4n+1). This is in effect the mirror image of :nth-child.

In place of the an+b formula, there are two keywords permitted: even and odd. These are equivalent to 2n and 2n+1, respectively.

Examples:

*:nth-last-child(4n+1) {font-weight: bold;}
tbody tr:nth-last-child(odd) {background-color: #EEF;}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required