2013-02-15 50 views
1

類似:如何爲一個以上的標籤分配班級?

HTML:

<tr class = "foo"> 
    <td class = "foo"> ... </td> 
    <td class = "foo"> ... </td> 
</tr> 

樣式表:

tr.foo, td.foo { /* all these rules apply to both */ } 

當然,這並不排除:

// I want to merge these 
tr.foo { ... } 
td.foo { ... } 

回答

2

您可以在CSS中使用逗號組合規則集你從其他規則集包括另一個tr.footd.foo,或覆蓋級聯中的規則。

如果你想使用的後代選擇,它只是一個空間:

tr.foo td.foo { /* affects all td class=foo children of tr class=foo */ } 

也有更具體的子選擇>

+0

謝謝,我應該使用逗號分隔符。 – thkang 2013-02-15 06:16:33

3

只是使用.foo{/*styles in here*/}沒有必要指定標籤

+0

那麼,除非你試圖指定標籤。 – 2013-02-15 06:13:27

+0

基於標題它看起來不是那樣的情況。 – Josh 2013-02-15 06:14:54

0
<tr id="trow" > 
    <td id="tcol">...</td> 
    <td id="tcoll">..</td> 
</tr> 

CSS

#trow,#tcol,#tcoll { 
------------- 
------------- 
} 

你提到的類名相同..

foo { 
--------- 
--------- 
} 

就足夠了。如果風格相同,則不需要合併。

相關問題