Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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
Html 如何排除第n个选择器?_Html_Css - Fatal编程技术网

Html 如何排除第n个选择器?

Html 如何排除第n个选择器?,html,css,Html,Css,假设我有这个: 我想为每个div添加绿色,除了倍数为3的div?是否可以使用nth-child()或其他方法来实现这一点 这应该有效: :not(:nth-child(3n)) 这应该起作用: :not(:nth-child(3n)) 您可以使用:nth-child()和:not()伪类执行此操作,伪类将选择除第三个div div:not(:第n个子项(3n)){ 颜色:绿色; } Div Div Div Div Div Div您可以使用:nth-child()和:not()伪类执行此操

假设我有这个:

我想为每个div添加绿色,除了倍数为3的div?是否可以使用
nth-child()
或其他方法来实现这一点

这应该有效:

:not(:nth-child(3n))
这应该起作用:

:not(:nth-child(3n))

您可以使用
:nth-child()
:not()
伪类执行此操作,伪类将选择除第三个
div

div:not(:第n个子项(3n)){
颜色:绿色;
}
Div
Div
Div
Div
Div

Div
您可以使用
:nth-child()
:not()
伪类执行此操作,伪类将选择除第三个
Div

div:not(:第n个子项(3n)){
颜色:绿色;
}
Div
Div
Div
Div
Div
Div
这工作正常

div:nth-child(3n) {
background: black;
}这工作正常

div:nth-child(3n) {
background: black;

}

可能重复的可能重复的感谢先生@Nenad VracarThank you先生@Nenad VracarThank you先生@samir Chahine谢谢先生@samir Chahine