La pseudo-class CSS :nth-last-of-type()
coincideix amb un o m茅s elements d'un tipus determinat, en funci贸 de la seva posici贸 entre un grup de germans, comptant des del final.
/* Selecciona cada quart element <p> entre qualsevol grup de germans, comptant enrere des de l'煤ltim */
p:nth-last-of-type(4n) {
color: lime;
}
Nota: Aquesta pseudo-class 茅s b脿sicament la mateixa que :nth-of-type
, excepte que compta els elements a l'inrev茅s des del final i no cap a endavant des del principi.
Sintaxi
La pseudo-class nth-last-of-type
s'especifica amb un sol argument, representa el patr贸 per als elements coincidents, comptant des del final.
Vegeu :nth-last-child
per obtenir una explicaci贸 m茅s detallada de la seva sintaxi.
Sintaxi formal
Exemple
HTML
<div>
<span>This is a span.</span>
<span>This is another span.</span>
<em>This is emphasized.</em>
<span>Wow, this span gets limed!!!</span>
<strike>This is struck through.</strike>
<span>Here is one last span.</span>
</div>
CSS
span:nth-last-of-type(2) {
background-color: lime;
}
Resultat
Especificacions
Especificaci贸 | Estat | Comentari |
---|---|---|
Selectors Level 4 The definition of ':nth-last-of-type' in that specification. |
Working Draft | No es requereix que els elements coincidents tinguin un pare. |
Selectors Level 3 The definition of ':nth-last-of-type' in that specification. |
Recommendation | Definici贸 inicial. |
Navegadors compatibles
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Descripci贸 | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Suport b脿sic | 4.0 | (Yes) | 3.5 (1.9.1) | 9.0 | 9.5 | 3.2 |
Descripci贸 | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport b脿sic | 2.1 | (Yes) | 1.0 (1.9.1) | 9.0 | 10.0 | 3.2 |