:nth-last-of-type()

:nth-last-of-type() – pseudo-class | Selectors Level 3

The :nth-last-of-type(an+b) selects last child of its parent element but this child elements is of the specified type. The pattern (an+b) for selected children works the same as for :nth-of-type() but the counting begins form the bottom parent element.

Syntax

element:nth-last-of-type(an+b) {
    style properties
}

Examples

The HTML code

<div>
    <div>div - 1, child 1</div>
    <div>div - 2, chld 2</div>
    <p>paragraph - 1, child 3</p>
    <p>paragraph - 2, child 4</p>
    <div>div - 1, child - 5</div>
    <p>paragraph - 3, child 6</p>
</div>
div div:nth-last-of-type(1) {
    background:#FFB7C5;
}

The last span element is selected.

div – 1, child 1
div – 2, child 2

paragraph – 1, child 3

paragraph – 2, child 4

div – 1, child – 5

paragraph – 3, child 6

Related

Resources

CSS Selectors Level 3

MDN

Browser compatibility

Internet Explorer
9.0
Firefox
3.5
Chrome
4.0
Safari
3.2
Opera
9.5
Mobile
Safari Mobile
works
Android
works
Chrome Mobile
works
IE Phone
works
Opera Mini
works
Opera Mobile
works