2013-10-17 64 views
0

我想让div的INSIDE reportRow的背景颜色具有特定的背景颜色,但我希望它切换每个其他reportRow的颜色。其他每个div的孩子的第n个孩子

我似乎无法得到第n个孩子的工作。谁能帮忙?

<div class="reportRow"> 
    <div style="width:75px;">Date1</div> 
    <div style="width:360px;">Address1</div> 
    <div style="width:40px;">Edit1</div> 
    <div style="width:40px;">Print1</div> 
    <div style="width:40px;">Delete1</div> 
</div> 

<div class="reportRow"> 
    <div style="width:75px;">Date2</div> 
    <div style="width:360px;">Address2</div> 
    <div style="width:40px;">Edit2</div> 
    <div style="width:40px;">Print2</div> 
    <div style="width:40px;">Delete2</div> 
</div> 
+0

你的CSS在哪里? –

回答

0

http://jsfiddle.net/bhlaird/t75Zu/
你想用第n个孩子上reportRow,但设置内div的背景

.reportRow:nth-child(2n) div { 
    background-color: blue; 
} 
+1

谢谢你,这完美的芭芭拉! – bryan

0

为目标每隔第n个孩子,这里有一个例子你应该怎么有你的CSS:

.reportRow:nth-child(even) { 
    background: #fff; 
} 

你可以用偶数或奇数以及其他一些东西来替换参数。以下是一些关于第十一个孩子假冒课程的文档:http://www.w3schools.com/cssref/sel_nth-child.asp