如何避免以下CSS重复:
div#logo div:nth-child(1) div {
width: 30%;
height: 30%;
background-color: white;
}
div#logo div:nth-child(3) div {
width: 30%;
height: 30%;
background-color: white;
}
Run Code Online (Sandbox Code Playgroud)
您可以将此用于1,3,5,7 ......就像div:nth-child(2n+1)从2(0)+ 1 = 1开始然后加2(1)+1 = 3,2(2)+ 1 = 5续...
div#logo div:nth-child(2n+1) div{
width: 30%;
height: 30%;
background-color: white;
}
Run Code Online (Sandbox Code Playgroud)