How can I style every third element with plain CSS.
I have seen questions like this, but they involve javascript. I want a plain CSS solution. I know I can use
section div:nth-child(3n+3) {
color: #ccc;
}
selected elements :
(3xn)+3 :
(3 x 0) + 3 = 3 = 3rd Element
(3 x 1) + 3 = 6 = 6th Element
(3 x 2) + 3 = 9 = 9th Element
etc.
you can read it as follow :
(select all third element) starting at 3
here you have all what you need as DEMO
http://css-tricks.com/examples/nth-child-tester/
read more here http://css-tricks.com/useful-nth-child-recipies/
http://css-tricks.com/how-nth-child-works/
Select Only Odd or Even:
section div:nth-child(odd) {
}
section div:nth-child(even) {
}
Select Only The First Five
div:nth-child(-n+5) {
}