CSS even odd for every other odd div in class

2019-06-17 05:26发布

问题:

I have divs in a horizontal row, all in the same class, like this:

1 2 3 4 5 6 7 8 9 10

What I want is to apply css to every other odd row, so 1,5,9, etc.

I've tried

.myClass:nth-child(n+4) and
.myClass:nth-child(odd),.myClass:nth-child(odd){

but can't figure it out :(

回答1:

:nth-child(4n) gives us 0, 4, 8, etc.

Since you want 1, 5, 9, you should try :nth-child(4n + 1)



回答2:

What you want to do is apply the css to every fourth row, so you want to do:

.myClass:nth-child(4n+1)