cheat/dev

:nth-child() / :first-child / :last-child

Selecionam elementos pela posição entre os irmãos.

Sintaxe

:first-child { }
:last-child { }
:nth-child(3n) { }

:nth-child(2n) pega pares, (2n+1) ímpares, (3n) todo terceiro. :nth-of-type ignora outros tipos de elemento na contagem, útil quando há tags diferentes misturadas.

Exemplo

li:first-child { margin-top: 0; }
li:last-child { border-bottom: none; }
tr:nth-child(3n) { background: #f3f4f6; }