写页面的时候常常会用到各种选择器,(ps:除了那种每个元素上面都写class的写法)。
那就来说说怎么在一个类或者id里面选择除了第一个元素以外的其他元素吧!
比如下面这种时候
在有序列表下面,分别给它们加上不同的背景颜色。
CSS里面可以这样写:
.icot ul li:nth-child(1){background-color:#ff3c41; }
.icot ul li:nth-child(2){background-color:#fe931d; }
.icot ul li:nth-child(3){background-color:#24bf34; }
.icot ul li:nth-child(4){background-color:#119aec; }或者是nth-of-type也可以实现还可以这样写 用元素叠加的方法也是可以实现的
.icot ul li{background-color:#ff3c41;}
.icot ul li+li{background-color:#fe931d;}
.icot ul li+li+li{background-color:#24bf34;}
现在颜色已经可以了,现在设置除了第一个元素以外的其他元素的边距,应该怎么写呢?
可能你们也已经想到啦 !可以这样.icot ul>li:not(:first-child){ margin-left: 2.3%;}这样,就可以达到我们想要的目的啦
上一篇: 高度设100%无效解决办法
下一篇: flexible.js实现移动端适配