:last-of-type

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Sumário

A CSS pseudo-class :last-of-type representa o último irmão com o nome de elemento dado na lista de filhos de seu elemento pai.

Syntax

element:last-of-type { style properties }

Exemplo

Para selecionar o último elemento em dentro de um elemento <p>, você pode usar o seguinte:

css
p em:last-of-type {
  color: lime;
}
html
<p>
  <em>I'm not lime :(</em>
  <strong>I'm not lime :(</strong>
  <em>I'm lime :D</em>
  <strong>I'm also not lime :(</strong>
</p>

<p>
  <em>I'm not lime :(</em>
  <span><em>I am lime!</em></span>
  <strong>I'm not lime :(</strong>
  <em>I'm lime :D</em>
  <span><em>I am also lime!</em> <strike> I'm not lime </strike></span>
  <strong>I'm also not lime :(</strong>
</p>

...irá resultar em:

Especificações

Specification
Selectors Level 4
# last-of-type-pseudo

Compatibilidade com navegadores

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
:last-of-type

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also