【问题标题】:Resize table header with contents使用内容调整表头大小
【发布时间】:2019-12-10 03:03:13
【问题描述】:

我有一个表格,里面有内容。我希望能够将列的大小调整为 0 像素,使其看起来“消失”。问题是由于标题和单元格内有内容,它只会缩小到内容的大小。

我只是想让它像这样工作:如果我将标题宽度设置为 10 像素,它应该变成 10 像素宽,无论标题或列内是什么。

我通过将单元格内容包装到一个绝对定位的容器中来解决问题:

 <table>
   <tr>
      <th style="width:0px">
          <div class="cell-wrapper">Some super long content</div>
      </th>

      <th>
          <div class="cell-wrapper">More content, could be an image</div>
      </th>
   </tr>
 </table>

 .cell-wrapper
 {
     position: absolute;
 }

但这种方法存在多个问题。有没有办法在没有绝对定位/容器解决方法的情况下做到这一点?谢谢!

【问题讨论】:

    标签: html css


    【解决方案1】:

    你可以试试这样的..

    .cell-wrapper {
      border: 1px solid black;
      }
      
     
     <table>
       <tr>
          <th style="display: table-column;">
              <div class="cell-wrapper">Some super long content</div>
          </th>
    
          <th>
              <div class="cell-wrapper">Another cell with long text</div>
          </th>
       </tr>
     </table>

    【讨论】:

    • 该列仍然折叠到与标题文本相同的宽度。如果我将标题宽度设置为 10 像素,我希望它为 10 像素,无论列内是什么
    猜你喜欢
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    相关资源
    最近更新 更多