写这篇文章的目的,主要是今天要实现一个布局:li,每行三个,总数不定,只能相邻的li之间需要10px的间距,效果如下图:
大家可以先自己实现一下,我这里也是思考了很久,最后整理了思绪,发现先给每个li添加margin-right:10px;然后给第3n个加上margin-bottom:10px;并且去掉margin-right,当然了,如果类似最后一个图,正好最后一排三个的情况,可能最后一行会超出,所以在li的last-child上加上margin-bottom:0;(最后一条是后面补充的,当时忘了加上去,不好意思)
代码:
li{
margin-right: 10px;
}
li:nth-child(3n){
margin-right: 0;
margin-bottom: 10px;
}
li:last-child{
margin-bottom:0;
}