有很多这方面的问题,但我无法找到以下解决方案:
<div class="row"></div>
<div class="noRow"></div>
<div class="row"></div>
<div class="noRow"></div>
<div class="row"></div>
<div class="noRow"></div>
<div class="row"></div>
<div class="noRow"></div>
...
我想更改每秒.row
我试过了:
.row:nth-child(odd)
没有任何改变
.row:nth-child(even)
更改所有.row
元素的背景颜色
答案 0 :(得分:3)
使用.row:nth-child(4n - 1)
或.row:not(:nth-child(4n + 1))
。
.row:nth-child(4n - 1) {
background-color: red;
}
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>
<div class="row">Row</div>
<div class="noRow">noRow</div>