I'm attempting to style list items in this particular order:
1: White
2: White
3: Blue
4: Blue
5: Blue
6: White
7: White
8: Blue
9: Blue
10: Blue
11: White
12: White
The pattern is [1-2] [3-4-5] [6-7] [8-9-10]
My html structure is just a simple list:
<ul> <li></li> <li></li> <li></li> <li></li> <li></li> </ul>
Is this pattern possible using css nth-child? If so what would my selector look like?
tr:nth-child(odd) or tr:nth-child(2n+1) Represents the odd rows of an HTML table: 1, 3, 5, etc. tr:nth-child(even) or tr:nth-child(2n) Represents the even rows of an HTML table: 2, 4, 6, etc.
The nth-of-type is very similar to the nth-child pseudo-class. The main difference is that it specifically considers the type of the element getting selected before checking any other logic. Let's use our example from above but apply nth-of-type instead.
Writing Complex :nth-child() SelectorsIt works exactly the same as :nth-child except that it starts from the end of the parent. For example, you can select the first three children of a parent by using the selector :nth-child(-n + 3) . You can use :nth-last-child(-n + 3) to select the last three.
Try:
ul li:nth-child(5n), ul li:nth-child(5n-1), ul li:nth-child(5n-2) { color:rgb(0,0,255); } ul li:nth-child(5n-3), ul li:nth-child(5n-4) { color:rgb(255,255,255); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With