有很多个li,li呈3个一行排列。现在需要控制最后一个li的样式(li:last-child),如果最后一个li是第1~3个,读a样式,如果是第4~6个,读b样式。循环下去 7~9读a,10~12读b... 纯css 如何取?
1 回答
繁花如伊
TA贡献2012条经验 获得超12个赞
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title></title>
<style>
li:last-child:nth-of-type(6n+1),li:last-child:nth-of-type(6n+2),li:last-child:nth-of-type(6n+3){ color: red;
} li:last-child:nth-of-type(6n+4),li:last-child:nth-of-type(6n+5),li:last-child:nth-of-type(6n){ color: yellow;
} </style></head><body><ul></ul><script>
var ul=document.querySelector('ul'); var index=1;
setInterval(function(){
ul.insertAdjacentHTML('beforeend',`<li>${index++}</li>`)
},500);</script></body></html>- 1 回答
- 0 关注
- 3176 浏览
添加回答
举报
0/150
提交
取消
