first-child
to select only the first child element:.my-list li:first-child {
background-color: red;
}
last-child
is used to select the last member from the list:my-list li:last-child {
background-color: blue;
}
nth-child(5)
is used to select nth
element. In the example we select 5th element.my-list li:nth-child(5) {
background-color: yellow;
}
We can also use nth-child(even)
to select even members from the list.my-list li:nth-child(even) {
background-color: grey;
}