Reputation:
I want to change the background-color first,fifth,seventh list item yellow and second,fourth,eighth list item green and third,sixth list item purple, How can I do it?
li:nth-child(2n+1){
background-color: yellow;
}
Upvotes: 0
Views: 424
Reputation: 11533
You can use the specificity and cascading rules of CSS to your advantage here:
yellow
.li {
background-color: yellow;
}
li:nth-child(even) {
background-color: green;
}
li:nth-child(3n+3) {
background-color: purple;
}
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<li>five</li>
<li>six</li>
<li>seven</li>
<li>eight</li>
</ul>
Upvotes: 2