有很多個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 關注
- 3150 瀏覽
添加回答
舉報
0/150
提交
取消