我需要改变第1节,第4节和第5节的背景颜色 cover-inner
我试过跟随,但它不起作用
.cover-wrapper .cover-inner:nth-of-type(4n+4) {
background-color: yellow;
}
.cover-wrapper .cover-inner:nth-of-type(4n+5) {
background-color: orange;
}
Run Code Online (Sandbox Code Playgroud)
把nth-of-type()上.cover-wrapper:
.cover-wrapper:nth-of-type(4n+4) .cover-inner {
background-color: yellow;
}
.cover-wrapper:nth-of-type(4n+5) .cover-inner {
background-color: orange;
}
Run Code Online (Sandbox Code Playgroud)
因为每个人.cover-inner都是其父母的唯一孩子,所以你永远不会被追赶.
附注:
:nth-of-type(4n)而不是:nth-of-type(4n+4):nth-of-type(5n)如果要更改每个第5个元素的颜色,则使用(目前,您正在更改每个第4个+ 1个元素的颜色):nth-of-type(1)或:first-of-type()定位第一个元素