2014-10-09 106 views
0

为每个TD元素在表上设置的奇数/偶数样式,但由于行跨度而不起作用。 尝试在http://jsfiddle.net/eFp7F/61/奇数行甚至奇数行

CSS样式:

.tablerow1 td { 
    background-color:#FFFFFF; 
} 
.tablerow2 td { 
    background-color:green; 
} 

HTML代码:

<table border="1"> 
    <tr> 
     <th>Type</th> 
     <th>Description</th> 
     <th>Number</th> 
    </tr> 
    <tr class="tablerow1"> 
     <td rowspan="1"><p>Cash</p></td> 
     <td><p>Cash</p></td> 
     <td><p>00000</p></td> 
    </tr> 
    <tr class="tablerow2"> 
     <td rowspan="2"><p>Receivables</p></td> 
     <td><p>Receivable</p></td> 
     <td><p>00</p></td> 
    </tr> 
    <tr> 
     <td><p>Accounts</p></td> 
     <td><p>0</p></td> 
    </tr> 
</table> 

怎么能解决这个问题?

+0

你想要帐户也是绿色的? – 2014-10-09 13:37:03

+2

你看起来像什么?你也想使用jQuery或只是CSS - 如果不删除jquery标签 – Rhumborl 2014-10-09 13:37:23

+0

样式工作,因为它们设置。 – Regent 2014-10-09 13:37:28

回答

0

您可以使用css来替代应用颜色。

.tablerow1 td:nth-child(even) { 
    background-color:#FFFFFF; 
} 
.tablerow2 td:nth-child(odd) { 
    background-color:green; 
} 
0

试伪元素:nth-of-typeDEMO

td:nth-of-type(odd) { 
    background-color:#666; 
} 
td:nth-of-type(even) { 
    background-color:green; 
} 
0

<td rowspan="2"><p>Receivables</p></td>标签有类 “tablerow2”。 即使它被涂抹在多行上,它仍然具有该类。