How to select childs elements

You can select one or more child elements via the nth-child(n) pseudo class selector.

Child elements are indexed from 1.

Click on code to see result.
// selects 5th item
#myList li:nth-child(5){
   ...
}
// selects every 3th item
#myList li:nth-child(3n){
   ...
}
// selects all items from 6th item
#myList li:nth-child(n+6){
   ...
}
// selects all items up to 6th item
// inclusive
#myList li:nth-child(-n+6){
   ...
}
// selects items in range
// [4; 8]
#myList li:nth-child(n+4):nth-child(-n+8){
   ...
}
  1. item 1
  2. item 2
  3. item 3
  4. item 4
  5. item 5
  6. item 6
  7. item 7
  8. item 8
  9. item 9