【问题标题】:table-layout:fixed issue表格布局:固定问题
【发布时间】:2012-03-19 16:18:55
【问题描述】:

我有一个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>

还有没有为剩余的行设置指定的列宽?

【问题讨论】:

    标签: css tablelayout


    【解决方案1】:

    这是因为固定表格布局是由第一行或列定义驱动的 - 试试这个

    <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>
    

    【讨论】:

    • 我需要这个列宽来为 body td 设置它。我在这里发布了一个问题。 stackoverflow.com/questions/9112849/….
    • 太棒了。有时您需要固定宽度的表格在 IE 上眩目
    • 有什么方法可以用纯 CSS 的方式做到这一点吗?我的网站中有数百个页面需要此更新,但我希望不必到处添加 &lt;col&gt; 标签
    【解决方案2】:

    您在th 上设置了宽度,为什么不在样式表中设置一个类来为thtr 行提供所需的宽度?

    【讨论】:

      【解决方案3】:

      试试这个

      <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-27
        • 1970-01-01
        • 2012-03-26
        • 2011-09-11
        • 2013-04-28
        相关资源
        最近更新 更多