2012-03-01 78 views
3

我有一個table,表格佈局已修復。表中有2列。表格佈局:已修復問題

如果我爲第一行設置了colspan=2,那麼對於其餘行,它將顯示相等的寬度。 (這不是我考慮指定的寬度)。

小提琴附着here

<table style='table-layout:fixed' border="1" width="100%"> 
    <thead> 
    <tr> 
     <th colspan='2'>10000</th> 
    </tr> 
    <tr> 
     <th width="5%">1066fdg</th> 
     <th width="95%">10</th> 
    </tr> 
    </thead> 
</table> 

反正是有設定其餘行指定的列寬?

回答

6

這是因爲固定表格佈局由第一行或列定義驅動的 - 嘗試這種

<table style='table-layout:fixed' border="1" width="100%"> 
<col width="5%" /> 
<col width="95%" /> 
<thead> 
<tr> 
<th colspan='2'>10000</th> 
</tr> 
<tr> 
<th>1066fdg</th> 
<th>10</th> 
</tr> 
</thead> 
</table> 
+0

我需要這個列的寬度來設置它對於身體TD的。我在這裏發佈了一個問題。 http://stackoverflow.com/questions/9112849/col-width-returns-0-for-ie-and-chrome。 – Sandy 2012-03-01 12:44:21

+0

輝煌。有時你需要固定寬度的表格*在IE瀏覽器*眩光* – agmin 2013-11-08 21:05:39

+0

任何方式以純粹的CSS方式做到這一點?我在一個網站中有數百頁需要這個更新,但我希望不必經過一個添加''標籤 – 2014-01-16 16:42:43

0

你有一個寬度上th設置何不在樣式表設置一個類來給thtr行是你需要的寬度嗎?

0

試試這個

<table style='table-layout:fixed' border="1" > 
<col width="5%" /> 
<col width="95%" /> 
<thead> 
<tr> 
<th colspan='2'>10000</th> 
</tr> 

<tr> 
<th>1066fdg</th> 
<th>10</th> 
</tr> 
    <tr><th>&nbsp</th><th>&nbsp</th></tr> 
</thead> 
</table>