Démo du selecteur nth-child, first-child et last-child en CSS

Sélection du premier élément
li:first-child { 
    background-color: #008080;
}
            
Sélection d'un élément spécifique
li:nth-child(2) { 
    background-color: #008080;
}
            
Sélection des 5 premiers éléments
li:nth-child(-n+5) { 
    background-color: #008080;
}
            
Sélection des 5 derniers éléments
li:nth-child(n+6) { 
    background-color: #008080;
}
            
Sélection tous les 3 éléments
li:nth-child(3n+1) { 
    background-color: #008080;
}
            
Sélection des éléments pairs
li:nth-child(even) { 
    background-color: #008080;
}
            
Sélection des éléments impairs
li:nth-child(odd) { 
    background-color: #008080;
}
            
Sélection du dernier éléments
li:last-child { 
    background-color: #008080;
}
            
Sélection de l'avant dernier élément
li:nth-last-child(2) { 
    background-color: #008080;
}