Fix table header at top of scrollable div

前端 未结 1 698
情深已故
情深已故 2021-01-27 09:02

The div in this example is scrollable, how do I make the header of the table fixed to the top of the div?

相关标签:
1条回答
  • 2021-01-27 09:34

    I would split into 2 sections and dictate the widths (% if responsive).

    <table id="table-top">
    <tr>
    <th>A</th>
    <th>B</th>
    </tr>
    </table>
    <div id="table">
    <table id="table_id">
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>
    </div>
    

    CSS....

    #table{
        overflow-y: auto; 
        height:150px;
        border-bottom:1px solid grey;
    }
    table{
        width:100%;
    }
    table td, table th{
        border-color: grey;
        border: 1px solid;  
        width:50%;
    }
    

    https://jsfiddle.net/tonytansley/mvp4u54q/

    0 讨论(0)
提交回复
热议问题