Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 nth-child() repeat range every 5 elements

It's possible to select a range of element each 5 elements? What i expect:

<ul>
   <li>Test</li>
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li>
   <li>Test</li>
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li>
</ul>

From 2 to 4, from 7 to 9, etc.

Thanks in advance!

like image 364
Alex Ferreli Avatar asked Dec 24 '22 08:12

Alex Ferreli


1 Answers

Since your range has the form [5 n - 3, 5 n - 2, 5 n - 1] (where n ≥ 1), use the following code:

li:nth-child(5n - 3), li:nth-child(5n - 2), li:nth-child(5n - 1) {
  color: red;
}
<ul>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
</ul>
like image 110
Alessio Cantarella Avatar answered Dec 27 '22 01:12

Alessio Cantarella