【问题标题】:Tables overflowing with CSS in FirefoxFirefox 中的表格溢出 CSS
【发布时间】:2010-12-11 12:59:40
【问题描述】:

我无法让我的表正常运行。内容不断溢出,我试图限制它并没有产生预期的效果。

这是我的标记:

<div class="repeatingdiv">
 <div class="hastitle">Some title</div>  
 <div class="hastable">
  <table>
   <thead><tr><th></th></tr></thead>     
   <tfoot><tr><th></th></tr></tfoot>
   <tbody>   
    <tr>
     <td class="col1">Col 1</td>
     <td class="col2">Col 2</td>
     <td class="col3">Col 3</td>
    </tr>
   </tbody>
  </table>
 </div>
</div>

然后我就有了一些风格。 td's 溢出了,但我没有运气设置他们的overflow to hidden/auto。在包含该表的 hastable 类中设置溢出确实有更好的运气。但我仍然无法让Firefox 尊重 3 列的width 分布:30%, 35%, 35%。我也尝试设置min-width,但仍然没有运气。我在页面上有几个这样的表格,每个表格都有自己的宽度。对这个乱七八糟的桌子有什么帮助吗?

.repeatingdiv { }
.hastitle      { margin:0 10px; padding:3px 3px 1px 6px; }       
.hastable      { overflow:hidden; 
                 text-overflow: ellipsis; 
                 margin:10px; 
                 padding:10px; 
               }
table          { }
table tbody    { width: 100%; }
tr    { width: 100%; }
td.col1     { width:30%; min-width:30%; }
td.col2  { width:35%; min-width:35%; }
td.col3  { width:35%; min-width:35%; }

【问题讨论】:

    标签: css firefox html-table overflow


    【解决方案1】:

    将表格包装在 div 中并为 div 设置溢出。

    <div style='overflow:scroll;'>
        <table>
          ...
        </table>
    </div>
    

    【讨论】:

      【解决方案2】:

      众所周知,表格很难设置样式。尝试将其添加到您的 CSS:

      table { table-layout: fixed; width: 100% /* or whatever fixed width */; }
      

      我还建议使用实际的 HTML COL / COLGROUP 元素来定义您的列,如下所示:

      <table>
       <colgroup class="col1" />
       <colgroup class="col2" />
       <colgroup class="col3" />
       <thead><tr><th></th></tr></thead>     
       <tfoot><tr><th></th></tr></tfoot>
       <tbody>   
        <tr>
         <td>Col 1</td>
         <td>Col 2</td>
         <td>Col 3</td>
        </tr>
       </tbody>
      </table>
      

      请注意,尽管如此,具有溢出数据的单元格强制包含的单元格、行和表格展开以适应。 CSS overflow: auto / hidden / scroll 不影响单元格。

      参考:

      【讨论】:

      • 溢出应该根据规范在单元格中工作。实际上,hidden 有效,但滚动无效,WebKit 除外。
      • 谢谢。我尝试在 td 元素中使用 white-space: nowrap ,我注意到即使我将宽度设置为 100%,表格的宽度也会突然膨胀;但是,在添加 table-layout: fixed 到解决问题的 CSS 之后!
      • table-layout: fixed; 在 FireFox 中保存了我的培根。谢谢!
      猜你喜欢
      • 2019-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      相关资源
      最近更新 更多