ul,li {
display: block;
margin:0;
padding:0;
list-style:none;
}
li {
background: black;
color: white;
padding: 10px;
}
li:nth-child(2n+2) {
background: red;
}
li:nth-child(3n+3) {
background: green;
}
li:nth-child(4n+4) {
background: blue;
}
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<li>five</li>
<li>six</li>
<li>seven</li>
<li>eight</li>
<li>nine</li>
<li>ten</li>
<li>eleven</li>
<li>twelve</li>
</ul>
我需要什麼:
- 黑
- 紅色
- 綠色
- 藍色
- 黑色
- 紅色
- 綠色
- 藍色
- ...
...我怎麼用:nth-child
實現這一目標?
據我所知'[的#]'語法不被任何支持呢。 –
Oriol
@Oriol tbh我從[MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child)獲得了語法,但是在選擇器級別4中似乎是WD [link ](https://drafts.csswg.org/selectors-4/#nth-child-pseudo) – dippas
感謝您的解釋! – 3zzy