CSS3: nth-last-child () selector
CSS selectors complete reference manual
Examples
P specifies that each element of the same type of match penultimate two sibling siblings background color:
{
background: # ff0000;
}
try it"
Definition and Usage
: Nth-last-of-type (n) selector to match the same type of reciprocal n-th sibling siblings.
ncan be a number, a keyword, or a formula.
Tip: See : nth-last-of-type () selector.The selector matches the parent element in the penultimate n structural sub-elements.
Browser Support
Figures in the table represent the first browser to support the version number of the property.
选择器 | |||||
---|---|---|---|---|---|
:nth-last-child() | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
More examples
Example 1
Odd and even can be used as a keyword to match the sub-element is used, its index is odd or even.
Here, we specify two different background colors for the odd and even reciprocal p elements:
{
background:#ff0000;
}
p:nth-last-child(even)
{
background:#0000ff;
}
try it"
Example 2
Using the formula (an + b) Description: The size of a representative of a cycle, N is a counter (starting at 0), and b is the offset.
Here we all indexes are multiples of three p element specifies the order of the inverse of the background color:
{
background: # ff0000;
}
try it"