Selettore CSS :first-child e:last-child

Pagina di prova dei selettori :first-child e :last-child - selezione del primo o ultimo elemento figlio

NB: NON supportato da Internet Explorer 6.
:last-child NON supportato da Internet Explorer 7 e Safari 3.0

Articolo completo sui selettori CSS su css.FlepStudio.org

Ritorna alla lista delle pagine di prove dei selettori css su Onsitus.it.

1. :first-child - Esempio per selezionare il primo paragrafo d'un elemento div

Regola css:

#esempio1 p:first-child{
font-style: italic;
color: red;
}

Sono un paragrafo, primo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Sono un paragrafo, secondo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Sono un paragrafo, terzo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

2. :last-child - Esempio per selezionare l'ultimo paragrafo d'un elemento div

Regola css:

#esempio2 p:last-child{
font-style: italic;
color: red;
}

Sono un paragrafo, primo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Sono un paragrafo, secondo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Sono un paragrafo, terzo ed ultimo figlio dell'elemento div
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.