Table fixed header and scrollable body

前端 未结 29 1737
粉色の甜心
粉色の甜心 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 05:59

    Likely you'll get multiple tables on one page, therefore you need CSS classes. Please find a modified @giulio's solution for that.

    Just declare it in table:

    CSS

    .header-fixed {
        width: 100% 
    }
    
    .header-fixed > thead,
    .header-fixed > tbody,
    .header-fixed > thead > tr,
    .header-fixed > tbody > tr,
    .header-fixed > thead > tr > th,
    .header-fixed > tbody > tr > td {
        display: block;
    }
    
    .header-fixed > tbody > tr:after,
    .header-fixed > thead > tr:after {
        content: ' ';
        display: block;
        visibility: hidden;
        clear: both;
    }
    
    .header-fixed > tbody {
        overflow-y: auto;
        height: 150px;
    }
    
    .header-fixed > tbody > tr > td,
    .header-fixed > thead > tr > th {
        width: 20%;
        float: left;
    }
    

    Be aware that current implementation suits five columns only. If you need a different number, change the width parameter from 20% to *100% / number_of_columns*.

提交回复
热议问题