If you've experimented with using :nth-child(3n)
but found it didn't quite achieve the desired outcome, here's a solution tailored to your needs:
Take a look at the following code snippet:
li{
height: 30px;
border: 2px solid #000;
&:nth-child(9n + 1),
&:nth-child(9n + 2),
&:nth-child(9n + 3){
background: green;
}
&:nth-child(9n + 4),
&:nth-child(9n + 5),
&:nth-child(9n + 6){
background: red;
}
&:nth-child(9n + 7),
&:nth-child(9n + 8),
&:nth-child(9n + 9){
background: blue;
}
}
Even though it might seem like you're dealing with groups of 3, in actuality, it's groups of 9 that are repeating. This is due to having 3 sets of 3 elements, resulting in a total of 9.
nth:child(9n)
This selector will pinpoint every 9th element. All that's left to do is increment this setup to handle the initial 3 elements, then the subsequent 3, and finally the last 3.