如果你想有一個棋盤,然後使用:
ul li:nth-child(8n+1), ul li:nth-child(8n+3), ul li:nth-child(8n+6), ul li:nth-child(8n+8) {
background-color:#ececec;
}
圖案每兩行,而你的情況是每8個元素重複,所以你在選擇需要8N。而在那八個中,你想要0,2,5和7有替代顏色。
編輯:我想這HTML,並得到了在Firefox 3.5.9棋盤:
<html>
<head>
<style>
#container {
width: 960px;
border: 1px solid black;
}
span {
border: 1px solid gray;
display: block;
width: 180px;
float: left;
padding: 10px;
margin: 10px;
background: blue;
}
span:nth-child(8n+1), span:nth-child(8n+3), span:nth-child(8n+6), span:nth-child(8n+8) {
background: red;
}
</style>
<body>
<div id='container'>
<span>One</span>
<span>Two</span>
<span>Three</span>
<span>Four</span>
<span>Five</span>
<span>Six</span>
<span>Seven</span>
<span>Eight</span>
<span>Nine</span>
<span>Ten</span>
<span>Eleven</span>
<span>Twelve</span>
<span>Thirteen</span>
<span>Fourteen</span>
<span>Fifteen</span>
<span>Sixteen</span>
<span>Seventeen</span>
<span>Eighteen</span>
</div>
反直覺,'第n-child'是從1開始的。 – bobince 2010-04-20 21:31:47
似乎無法得到這個工作。仍然加載完全相同。要多給它幾次嘗試 – JCHASE11 2010-04-20 21:44:53
我已經嘗試了兩種建議,每種可能的組合都有,並且它仍然沒有工作......任何想法? – JCHASE11 2010-04-20 21:47:39