CSS :nth-last-of-type() Selector
Example
/* Sets the background color to red on the second to last p element of its parent */
p:nth-last-of-type(2) {
background: red;
}
Meaning
The :nth-last-of-type() selector selects the element that is the nth-from-last child of its parent that is its type.
The :nth-last-of-type() pseudo-class is specified with a single argument, which represents the pattern for matching elements, counting from the end.
Version: CSS3
Standard Syntax
:nth-last-of-type(n|odd|even) {
css declarations;
}
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Status
Parameter values
The following table describes the values of this selector parameter.
Value | Description |
---|---|
n | Specifies the number to selects the element that is the nth-from-last child of its parent that is its type. |
odd | Defines elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc. |
even | Defines elements whose numeric position in a series of siblings is even: 2, 4, 6, etc. |