在我的表格中,我设置列中第一个单元格的宽度为100px。 但是,当此列中的某个单元格中的文本太长时,列的宽度就会超过100px。如何禁用此扩展?


当前回答

看到的: http://www.html5-tutorials.org/tables/changing-column-width/

在table标记之后,使用col元素。不需要结束标记。

例如,如果你有三列:

<table>
  <colgroup>
    <col style="width:40%">
    <col style="width:30%">
    <col style="width:30%">
  </colgroup>  
  <tbody>
    ...
  </tbody>
</table>

其他回答

你不需要设置“fixed”-你只需要设置overflow:隐藏,因为列宽度已经设置好了。

我所做的是:

设置td宽度: <td width="200" height="50"><!——blaBlaBla这里的内容——></td> . txt 使用CSS设置td宽度: < td风格= "宽度:200 px;高度:50 px;" > 用CSS再次设置宽度为max和min: < td风格= " max-width: 200 px;min-width: 200 px;max-height: 50 px;最小高度:50 px;宽度:200 px;高度:50 px;" >

这听起来有点重复,但它给了我想要的结果。为了更容易地实现这一点,你可能需要把CSS值放在样式表中的一个类中:

.td_size {    
  width:200px; 
  height:50px;
  max-width:200px;
  min-width:200px; 
  max-height:50px; 
  min-height:50px;
  **overflow:hidden;** /*(Optional)This might be useful for some overflow contents*/   
}

然后:

<td class="td_size">

将class属性放置到任何<td>。

凯旋的想法是对的。这是正确的代码…

<style type="text/css">
  th.first-col > div, 
  td.first-col > div {
    overflow:hidden;
    white-space:nowrap;
    width:100px
  }
</style>

<table>
  <thead><tr><th class="first-col"><div>really long header</div></th></tr></thead>
  <tbody><tr><td class="first-col"><div>really long text</div></td></tr></tbody>
</table>

设置:

style="min-width:100px;" 

为我工作。

看到的: http://www.html5-tutorials.org/tables/changing-column-width/

在table标记之后,使用col元素。不需要结束标记。

例如,如果你有三列:

<table>
  <colgroup>
    <col style="width:40%">
    <col style="width:30%">
    <col style="width:30%">
  </colgroup>  
  <tbody>
    ...
  </tbody>
</table>