2013-02-03 30 views
0

共同Html表的CSS?

table tr td 
{ 
    vertical-align:middle; 
} 

定製

table.custom tr td 
{ 
    vertical-align:top; 
} 

當我使用這樣的:

<table class="custom"> 
    <tr> 
     <td> 
      <table> 
       <tr> 
        <td>this text align top, but I want to align middle 
        </td> 
       </tr> 
      </table> 
     </td> 
    </tr> 
</table> 

子錶行爲像其父。如何忽略父元素樣式?

回答

1

一件事,你所能做的就是將孩子選擇像這樣:

table.custom > tr > td { } 

然後只顧眼前的孩子們將匹配風格

1

可以使用>指標只針對直接子元素

table.custom > tr > td 
{ 
    vertical-align:top; 
} 

然而,應當注意的是,使用一個tabletable是基因集會不是一個好主意。注2:這在IE6中不起作用。