2016-11-17 3 views
1

Ich möchte hinzufügen auf dritte tr in table mit CSS nicht Inline-Stil.CSS in HTML-Tabelle hinzufügen?

Kann mir jemand helfen?

unter meinem HTML-Code:

<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> 

Dank

+1

zeigen Sie uns etwas, was Sie ausprobiert haben? – kukkuz

Antwort

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>
zugegriffen wird,

0

Sie können es mit dieser Selektor:

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

:nth-child(n) akzeptiert eine Reihe und es ist einer basiert, das heißt das erste Kind mit 1