Css 正在查找第n个子样式的表达式
我想为4个一组的子元素设置样式。我需要在第n个子样式中使用什么表达式?下表每四个元素更改一次样式。我想要前四个黑/白,后四个白/黑,等等Css 正在查找第n个子样式的表达式,css,Css,我想为4个一组的子元素设置样式。我需要在第n个子样式中使用什么表达式?下表每四个元素更改一次样式。我想要前四个黑/白,后四个白/黑,等等 ul li:nth-child(4n) { background-color: black; color: white; } ul li:nth-child(4n+1) { background-color: white; color: black; } 有可能有更好的方法,但这会起作用: ul li:nth-child(8n+1), ul
ul li:nth-child(4n) {
background-color: black;
color: white;
}
ul li:nth-child(4n+1) {
background-color: white;
color: black;
}
有可能有更好的方法,但这会起作用:
ul li:nth-child(8n+1),
ul li:nth-child(8n+2),
ul li:nth-child(8n+3),
ul li:nth-child(8n+4){
background-color: black;
color: white;
}
可能有更好的方法,但这会起作用:
ul li:nth-child(8n+1),
ul li:nth-child(8n+2),
ul li:nth-child(8n+3),
ul li:nth-child(8n+4){
background-color: black;
color: white;
}