我有一个divs与类连续显示4 的列表,我想创建一个棋盘背景样式,其含义是:
divs我已经试过了
.boxwrapper:nth-child(2n-1), .boxwrapper:nth-child(2n) {
background:#ff0000;
}
.boxwrapper:nth-child(4n-2), .boxwrapper:nth-child(4n-3) {
background:#0000ff;
}
Run Code Online (Sandbox Code Playgroud)
它适用于奇偶div,但无法使其每4个项目切换一次。如果我能得到正确的结果,我正在研究4n-1、4n + 1的东西!
结果应如下所示:

<div class="container">
<div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
<div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
<div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
<div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
</div>?
Run Code Online (Sandbox Code Playgroud)
.container {
width: 100px;
height: 100px;
}
.line {
width: 100px;
height: 25px;
}
.box {
width: 25px;
height: 25px;
float: left;
}
.box:nth-child(8n+2) {
background-color: red;
}
.box:nth-child(8n+4) {
background-color: red;
}
.box:nth-child(8n+5) {
background-color: red;
}
.box:nth-child(8n+7) {
background-color: red;
}
.box:nth-child(8n+1) {
background-color: blue;
}
.box:nth-child(8n+3) {
background-color: blue;
}
.box:nth-child(8n+6) {
background-color: blue;
}
.box:nth-child(8n) {
background-color: blue;
}
?
Run Code Online (Sandbox Code Playgroud)
?
| 归档时间: |
|
| 查看次数: |
1774 次 |
| 最近记录: |