Last active
March 24, 2024 14:15
-
-
Save helabenkhalfallah/370f20b2dd53641df415c54fcd5270ac to your computer and use it in GitHub Desktop.
nth-child
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Select the 2nd child. */ | |
:nth-child(2) | |
/* Select all even children (2nd, 4th, 6th, 8th, and so on). */ | |
:nth-child(2n) | |
/* Select all odd children (1st, 3rd, 5th, 7th, and so on). */ | |
:nth-child(2n+1) | |
/* Select the 1st (=(5×0)+1), 6th (=(5×1)+1), 11th (=(5×2)+1), … child. */ | |
:nth-child(5n+1) | |
/* Select the 2nd (=(5×0)+2), 7th (=(5×1)+2), 12th (=(5×2)+2), … child. */ | |
:nth-child(5n+2) | |
/* Select every child from the 3rd one up (3rd, 4th, 5th, and so on). */ | |
:nth-child(n+3) | |
/* Select every child up to the 5th one (1st, 2nd, 3rd, 4th, 5th). */ | |
:nth-child(-n+5) | |
/* Select every child from the 3rd one up to the 5th one (3rd, 4th, 5th). */ | |
:nth-child(n+3):nth-child(-n+5) | |
/* Select the first list item */ | |
li:nth-child(1) { } | |
/* Select the 5th list item */ | |
li:nth-child(5) { } | |
/* Select every other list item starting with first */ | |
li:nth-child(odd) { } | |
/* Select every 3rd list item starting with first */ | |
li:nth-child(3n - 2) { } | |
/* Select every 3rd list item starting with 2nd */ | |
li:nth-child(3n - 1) { } | |
/* Select every 3rd child item, as long as it has class "el" */ | |
.el:nth-child(3n) { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment