效果预览:
一、基础的代码结构
<div class="box">
<div class="box-item">1</div>
<div class="box-item">2</div>
<div class="box-item">3</div>
</div>
<style>
.box {
display: flex;
}
.box .box-item {
display: flex;
align-items: center;
justify-content: center;
margin: 20px 10px;
width: 100px;
height: 100px;
background: #f00;
font-size: 20px;
}
</style>
二、实现方式
1 :not ()
/* 方法1 */
.box .box-item:not(:first-child) {
background: #097fff;
}
2 :nth-of-type()
/* 方法2 */
.box .box-item:nth-of-type(n+2) {
background: #097fff;
}
3 :nth-child()
/* 方法3 */
.box .box-item:nth-child(n+2) {
background: #097fff;
}
4 ~
/* 方法4 */
.box .box-item:first-child ~ .box-item {
background: #097fff;
}
~ 选择器 :是查找某个指定元素后面的兄弟节点