Select only the first elements use the selector nth-child in CSS

Select only the first elements use the selector nth-child:

Example, we select only the first three elements and fill them with green color with the css codes like this:

li:nth-child(-n+3) {
  background-color: green;   
}


Result:



Read more: Select only the last elements use the selector nth-child in CSS

csscss selectorcss3nth-child

© 2019 4codev

Created with love by Sil.