我需要对列表中的每四个元素应用某种样式:
现在我有:
.panel:nth-child(1) {background:#F0A46A;}
.panel:nth-child(2) {background:#EE8020;}
.panel:nth-child(3) {background:#BB6619;}
.panel:nth-child(4) {background:#887A4B;}
我希望在第 5、6、7、8(依此类推)中再次重复此行为,与第 1、2、3、4 相同
最佳答案
ul li:nth-child(4n +1) {background:red;}
ul li:nth-child(4n +2) {background:blue;}
ul li:nth-child(4n +3) {background:green;}
ul li:nth-child(4n +4) {background:orange;}
关于css nth-child 四对四,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22990365/