2009-05-05 35 views
2

那么可以说,我有这个CSS嵌套不工作,我希望它的方式!

<table class="infoBox"> 
    <tr> 
     <td> 
      test 
     </td> 
     <td> 
      <table> 
       <tr> 
        <td> 
         this should not be bold! 
        </td> 
       </tr> 
      </table> 
     </td> 
    </tr> 
</table> 

然后我们得到了一些CSS这个

Table.infoBox TR TD { 字体重量:大胆的; }

我现在的问题是,嵌套表似乎对CSS还当我只想要外部表得到这个CSS我如何的方式定义它,这样嵌套表不会受到CSS ?

回答

6

虽然你可以用直接的孩子做到这一点,但这并不是所有浏览器都支持的。尝试:

table.infoBox tr td { font-weight: bold; } 

table.infoBox table tr td { font-weight: normal; } 

所有的选择table.infoBox tr td说的是:

应用该样式的任何<td>标签,它是任何<tr>标签,这是任何表的一类信息框的孩子的孩子。

因此,您需要在此样式块下面获取更具体的信息,以便声明您希望对类infoBox的表中的表执行什么操作。

3

要么使用子选择:

table.infoBox > tbody > tr > td { font-weight: bold; } 

(在IE6不支持)

注:神秘tbody元素。这是由浏览器插入的,如果你没有插入。这是因为表格有三个部分:thead, tbody and tfoot。如果没有其中一个,行被添加到tbody元素。

或组合:

table.infoBox tr td { font-weight: bold; } 
table.infoBox tr td td { font-weight: normal; } 

有此一个的许多潜在变化。

2

Table.infoBox table tr td {font-weight:normal; }

1

它也可以足够使用:

table.infoBox { font-weight: bold; } 
table.infoBox table { font-weight: normal; } 

table.infoBox tr { font-weight: bold; } 
table.infoBox table tr { font-weight: normal; } 

虽然所有的CSS取决于整个CSS其他字体重规则,它的方便需要注意的是CSS declerations基于在decendensy,而不是直接的父母子女关系。因此,table{}只会对td{}的内容具有相同的效果,只要您没有更强或更接近所定义内容的内容即可。