Hey. I can not figure out the formula required for the selection of elements:

1,4,7 2,5,8 3,6,9 

I tried to do 1n, 2n и 3n and 1n+3, 2n+3, 3n+3 , but it did not work.

1 answer 1

 li { color: #000; } li:nth-child(3n-2) { color: red; } li:nth-child(3n-1) { color: blue; } 
 <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> </ul>