0

我必须用滚动条制作这个表格内容(tbody),表格的高度是固定的。为了启用滚动,我添加了样式display: block。之后,表格的宽度被冻结且不可调整。给我找个办法让表格的宽度变满。

目前该表看起来像

HTML:

   <table class="table table-striped table-hover" id="item_table">
       <thead>
        <tr class="bg-primary">
         <th>#</th>
          <th>Product Name</th>
          <th>Quantity</th>
          <th>Unit Price</th>
          <th>Discount</th>
          <th>Amount</th>
          <th><i class="fa fa-close"></i></th>
         </tr>
   </thead>
   <tbody id="item_list">
     <tr>
       <td>1</td>
       <td>Mens Full Sleeve Shirts</td>
       <td>1</td>
       <td>2200.00</td>
       <td>200.00</td>
       <td>2000.00</td>
       <td><span><i class="fa fa-trash"></i></span></td>
     </tr>
   </tbody>
</table>

CSS:

#item_table{
    display: table-row;
    table-layout:fixed;
}

#item_list{
    width: 100%;
    display: block;
    table-layout:fixed;
    height: 170px;
    overflow-y: scroll;
}
4

2 回答 2

2

不要添加display:block到表中。它会摧毁它。

将表格 Insteed 包装成 adiv并添加 overflow:auto到此元素。

或者,如果使用引导程序,请将类添加到容器中,如您在此处table-responsive的文档中所见

于 2020-02-05T16:37:38.150 回答
0

嗨,请试试这个:

tbody {
    height: 100px;       /* Just for the demo          */
    overflow-y: auto;    /* Trigger vertical scroll    */
    overflow-x: hidden;  /* Hide the horizontal scroll */
}
于 2020-02-07T05:53:18.130 回答