2016-11-17 57 views
1

我想添加backbround-color在第三個trtable使用CSS不內聯樣式。在HTML表格中添加CSS?

任何人都可以幫我嗎?

下面我的html代碼:

<table> 
    <tr> 
    <td>First TR</td> 
    </tr> 
    <tr> 
    <td>Second TR</td> 
    </tr> 
    <tr> 
    <td>Third TR</td> 
    </tr> 
    <tr> 
    <td>Four TR</td> 
    </tr> 
    <tr> 
    <td>Fifth TR</td> 
    </tr> 
</table> 

感謝

+1

告訴我們你試過的東西嗎? – kukkuz

回答

1

table>tbody>tr:nth-child(3) { 
 
background-color:red; 
 
}
<table> 
 
    <tr> 
 
    <td>First TR</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Second TR</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Third TR</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Four TR</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Fifth TR</td> 
 
    </tr> 
 
</table>
訪問

0

你可以做到這一點這個選擇器:

table tr:nth-child(3){ 
    background-color: #rgb; /*your color */ 
} 

:nth-child(n)接受許多並且它基於一個,即第一子 與1