【发布时间】:2021-07-23 13:23:22
【问题描述】:
我已经构建了一个示例页面,如下所示。但是框的颜色是通过选择特定的框来分配的。
body, *{
box-sizing: border-box;
}
.container{
width:200px;
margin:0px auto;
}
.box{
width:100px;
height:100px;
float:left;
}
.box:nth-child(1){
background-color:red;
}
.box:nth-child(2){
background-color:green;
}
.box:nth-child(3){
background-color:green;
}
.box:nth-child(4){
background-color:red;
}
.box:nth-child(5){
background-color:red;
}
.box:nth-child(6){
background-color:green;
}
.box:nth-child(7){
background-color:green;
}
.box:nth-child(8){
background-color:red;
}
<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>
我想更改它,以便在添加新框或删除任何框时,红绿模式不会中断。我该怎么做?
【问题讨论】: