2012-03-01 81 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>