Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nth-child to select an even, and then an odd number of elements

Tags:

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?

like image 256
Adam Soffer Avatar asked Dec 01 '14 16:12

Adam Soffer


People also ask

What is nth child odd?

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.

What's the difference between the nth of type () and Nth child () selectors?

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.

How do you use the nth child in sass?

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.


1 Answers

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); } 
like image 173
Rounin - Glory to UKRAINE Avatar answered Sep 19 '22 05:09

Rounin - Glory to UKRAINE