2010-09-16 12 views
13

Sagen Sie zum Beispiel habe ich:Auswählen ersten td in der ersten Tabelle mit CSS 3

<div id="container"> 
    <table> 
     <tr> 
      <td></td> 
      <td></td> 
     </tr> 

     <tr> 
      <td></td> 
      <td></td> 
     </tr> 
    </table> 

    <table> 
     <tr> 
      <td></td> 
      <td></td> 
     </tr> 

     <tr> 
      <td></td> 
      <td></td> 
     </tr> 
    </table> 
</div> 

Und

td { width:10px; height:10px; } 

Was ich will ist ein Stil auf die erste td tun gilt, von der erste Tabelle.

ich erwartet hätte:

#container table:first-child td:first-child { 
    background: red; 
} 

Allerdings funktioniert es nicht? Bitte beraten!

Antwort

32
#container table:first-child tr:first-child td:first-child { background: red; } 

Scheint zu arbeiten.
Beachten Sie, dass unter IE, müssen Sie eine! DOCTYPE-Deklaration in Ihrem HTML haben, um Unterstützung für: First-Kind. http://www.w3schools.com/cssref/sel_firstchild.asp

Verwandte Themen