Table fixed header and scrollable body

前端 未结 29 1735
粉色の甜心
粉色の甜心 2020-11-22 05:33

I am trying to make a table with fixed header and a scrollable content using the bootstrap 3 table. Unfortunately the solutions I have found does not work with bootstrap or

29条回答
  •  臣服心动
    2020-11-22 06:08

    Used this link, stackoverflow.com/a/17380697/1725764, by Hashem Qolami at the original posts' comments and used display:inline-blocks instead of floats. Fixes borders if the table has the class 'table-bordered' also.

    table.scroll {
      width: 100%;  
      &.table-bordered {
        td, th {
          border-top: 0;
          border-right: 0;
        }    
        th {
          border-bottom-width: 1px;
        }
        td:first-child,
        th:first-child {
          border-right: 0;
          border-left: 0;
        }
      }
      tbody {
        height: 200px;
        overflow-y: auto;
        overflow-x: hidden;  
      }
      tbody, thead {
        display: block;
      }
      tr {
        width: 100%;
        display: block;
      }
      th, td {
        display: inline-block;
    
      }
      td {
        height: 46px; //depends on your site
      }
    }
    

    Then just add the widths of the td and th

    table.table-prep {
      tr > td.type,
      tr > th.type{
        width: 10%;
      }
      tr > td.name,
      tr > th.name,
      tr > td.notes,
      tr > th.notes,
      tr > td.quantity,
      tr > th.quantity{
        width: 30%;
      }
    }
    

提交回复
热议问题