table表头固定

table表头固定

方式一

<style>
    table tbody {
        display:block;
        height: 600px;/* 需要固定高度 */
        overflow-y:auto;
        overflow-x: hidden;
    }
    table thead, tbody tr {
        display:table;
        width:100%;
        table-layout:fixed;
    }
    table thead {
        width: calc( 100% - 1em )
    }
</style>

方式二

<div id="table-cont" style="overflow-y: auto;">
    <table>
    <thead>
        <tr>
            <th>名称</th>
            <th>类型</th>
            <th>大小</th>
            <th>最后修改时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody id="privateDir_table"></tbody>
    </table>
</div>
 window.onload = function () {
        $("#table-cont").css("height", $(document.body).height() - 120);
        var tableCont = document.querySelector('#table-cont')

        function scrollHandle(e) {
            var scrollTop = this.scrollTop;
            this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
        }

        tableCont.addEventListener('scroll', scrollHandle)
}

 上一篇
spring文件下载 spring文件下载
spring文件下载package com.util; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; im
2019-08-19
下一篇 
table表格嵌套边框合并问题 table表格嵌套边框合并问题
table表格嵌套边框合并问题外层table与内层table嵌套,内外表格都需边框时,设置“border=1”,但边框会重复,造成某些地方边框粗,有些地方边框细的问题。 解决办法: 外表格样式: <table border="1" c
2019-08-19
  目录