Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 正在查找第n个子样式的表达式_Css - Fatal编程技术网

Css 正在查找第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

我想为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 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;
}