[英]Using nth-child to make a chess pattern
我想要在這里做一些相對簡單的事情。
我需要在頁面上選擇每個第3和第4個元素,我怎么能用css:nth-child()來做?
JS的答案也很受歡迎。
非常感謝。
***編輯
抱歉,我的問題寫得很糟糕。 我在下面附上了一個我需要的例子。
這是我需要的結果, http://jsfiddle.net/8FXL6/
<li></li>
<li class="highlight"></li>
<li class="highlight"></li>
<li></li>
<li></li>
etc
沒有硬編碼類名。
您可以使用逗號將使用nth-child的選擇器組合起來獲取元素,
elements = $('div .className :nth-child(3), div .className :nth-child(4)');
如何僅使用css?
每三個元素:
*:nth-child(3n+3) {color: red}
每四個要素:
*:nth-child(4n+4) {color: blue}
這是關於jsfiddle的演示: http : //jsfiddle.net/dufsx/
這可以僅使用CSS來解決
*:nth-child(4n+2){background:blue;color: white;}
*:nth-child(4n+3){background:blue;color: white;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.