2010-04-08 61 views
32

CSS爲什麼TR不採取風格?

table tr {border-bottom:1px solid #008999} 

HTML

<table width="100%" cellspacing="0" cellpadding="0"> 
    <thead> 
     <tr> 
     <th scope="col">one</th> 
     <th scope="col">two</th> 
     <th scope="col">three</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <th scope="row">Hello</th> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     </tr> 
    </tbody> 
</table> 
+0

重複:http://stackoverflow.com/questions/670424/border-around-specific-rows-in-a-table HTTP://計算器。 com/questions/583539/set-border-to-table-tr-works-in-everything-except-ie-6-7 http://stackoverflow.com/questions/2238174/border-bottom-for-ie-is -not-working-in-tr – 2010-04-10 09:19:35

回答

42

地址:

table 
{ 
    border-collapse: collapse; 
} 

否則trcreates no single block

簡單的例子:

table 
 
{ 
 
    border: 5px solid #900; 
 
    background: #fff; 
 
} 
 
tr 
 
{ 
 
    border: 5px solid #090; 
 
} 
 
td 
 
{ 
 
    background: #ccc; 
 
    padding: 5px 0; 
 
} 
 

 
table + table 
 
{ 
 
    border-collapse: collapse; 
 
}
<table> 
 
    <tr> 
 
    <td>def</td> 
 
    <td>ault</td> 
 
    </tr> 
 
</table> 
 
<table> 
 
    <tr> 
 
    <td>coll</td> 
 
    <td>apse</td> 
 
    </tr> 
 
</table>

+0

首先你找到了解決方案,所以我接受你的答案 – 2010-04-08 05:21:28

+0

爲什麼它必須被摺疊? @toscho – Cullub 2016-01-19 12:58:04

+0

@cullub請參閱代碼塊下的句子? – fuxia 2016-01-19 13:04:34

8

先給

table tr th {border-bottom:1px solid #008999} 

然後你可以使用

table { border-collapse: collapse; } 
table tr {border-bottom:1px solid #008999; } 

The collapsing border model

+0

我需要的不是 – 2010-04-08 05:09:03

+0

@ metal-gear-solid:你究竟在做什麼?你能描述一下你希望看到的視覺效果嗎? – 2010-04-08 05:21:31

+0

@raul - 見這個'table tr {border-bottom:1px solid#008999}'這意味着'table'中的每個'TR'都應該有'1px'高度'solid'和這個顏色'#008999'的邊界。什麼不清楚? – 2010-04-08 05:23:38

2

TR顧名思義不會採取邊框樣式。你需要在它把它應用到TD的:

table tr td {border-bottom:1px solid #008999} 
相關問題