寫頁面的時候常常會用到各種選擇器,(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實現移動端適配