2014-10-09 57 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」。 即使它被塗抹在多行上,它仍然具有該類。