css 伪类来确定子元素个数 实现不同个数的不同展示效果
- element:first-child:nth-last-child(2) 有两个子元素 即第一个元素也是倒数第二个元素
- element:first-child:nth-last-child(n) 有n个子元素
- father:has(son:nth-last-child(n):first-child) son 统一设置
例子:微信朋友圈上传图片展示效果纯css 完成
h2,p,ul,li{
padding:0;
margin:0;
}
ul,li{
list-style: none;
}
.vessel{
width:400px;
height: fit-content;
border:1px solid blue;
display: flex;
flex-flow: row nowrap;
background-color: #000;
margin:auto;
}
.left_box{
width:80px;
height:100%;
img{
width:60px;
height:60px;
object-fit:cover;
object-position: center;
vertical-align: middle;
border-radius: 8px ;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
display: block;
margin:10px 5px 0px auto;
}</