我有一个像这样的HTML模板:
<div id = "container">
<div class = "status">
<div class ="dynamic"></div>
</div>
<div class = "status">
<div class ="dynamic"></div>
</div>
<div class = "status">
<div class ="dynamic"></div>
</div>
<div class = "status">
<div class ="dynamic"></div>
</div>
</div>
是否可以使用CSS或jQuery更改其他.status
的{{1}}的背景?
答案 0 :(得分:2)
您可以在纯CSS中执行此操作:
#container > .status:nth-child(2n+1) > .dynamic {
/* Change the background */
}
答案 1 :(得分:1)
这可以通过CSS完成:
#container > .status:nth-child(2n) > .dynamic { background: whatever-you-want; }
或
#container > .status:nth-child(2n+1) > .dynamic { background: whatever-you-want; }
答案 2 :(得分:0)
尝试
$('.status:odd .dynamic').css('color', 'blue')
或
$('.dynamic:even').css('color', 'blue')
演示:fiddle