学习使用html中table实现内容滚动下拉表头和左右滑动前四列固定不动的方法代码整理

学习使用html中table实现内容滚动下拉表头和左右滑动前四列固定不动的方法代码整理

效果图

代码

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        table {
            border-collapse: collapse;
        }

        .sticky-table {
            overflow: auto;
            height: 400px; /* 设置固定高度 */
            width: 1000px;
            position: absolute
        }

        .sticky-table td, .sticky-table th {
            /* 设置td,th宽度高度 */
            border: 1px solid #c7d8ee;
            width: 150px;
            min-width: 150px;
            height: 30px;
            padding: 5px;
            /*边框线,不会随着滑动变化而滑动 start*/
            outline-color: #c7d8ee;
            outline-style: solid;
            outline-width: 1px;
            /*边框线,不会随着滑动变化而滑动 start*/
        }


        .sticky-table th {
            position: sticky;
            top: 0; /* 首行永远固定在头部  */
            background-color: #eaf4ff; /*设置表头背景色*/
        }

        .sticky-table td:first-child, .sticky-table th:first-child {
            position: sticky;
            left: 0; /* 首列永远固定在左侧 */
            z-index: 1;
            background-color: #eaf4ff;
        }

        .sticky-table th:first-child {
            z-index: 2; /*表头的首列要在上面*/
        }


        /*第二行*/
        .sticky-table td:nth-child(2) {
            position: sticky;
            left: 151px;
            z-index: 3;
            background-color: #eaf4ff;
            color: #22222;
        }

        /*第二列*/
        .sticky-table th:nth-child(2) {
            position: sticky;
            left: 151px;
            z-index: 4;
        }

        .sticky-table td:nth-child(3) {
            position: sticky;
            left: 301px;
            z-index: 3;
            background-color: #eaf4ff;
            color: #22222;
        }

        /*第三列*/
        .sticky-table th:nth-child(3) {
            position: sticky;
            left: 301px;
            z-index: 4;
        }

        /*第四列*/
        .sticky-table td:nth-child(4) {
            position: sticky;
            left: 451px;
            z-index: 3;
            background-color: #eaf4ff;
            color: #22222;
        }

        /*第四列*/
        .sticky-table th:nth-child(4) {
            position: sticky;
            left: 451px;
            z-index: 4;
        }

        .sticky-table th > div {
            width: 100%;
            white-space: normal; /*允许在单元格内正常换行。*/
            word-wrap: break-word; /*当单元格内的单词太长时,允许将单词拆分成多个行。*/
            word-break: break-all; /*允许在单元格内的单词内进行换行,而不仅限于字母间的换行。*/
        }

        /*.sticky-table table {
            table-layout: fixed;  布局为固定布局。这意味着表格的列宽和行高将保持不变
        }*/

    </style>
</head>
<body style="padding: 0px;margin: 0px;">
<div class="sticky-table">
    <table>
        <thead>
        <tr>
            <th></th>
            <th colspan="8">个人素养</th>
            <th colspan="4">社群素养</th>
            <th colspan="8">职业素养</th>
        </tr>
        <tr>
            <th></th>
            <th colspan="2">身体素质</th>
            <th colspan="2">艺术修养</th>
            <th colspan="2">心理素质</th>
            <th colspan="2">道德修为</th>
            <th colspan="2">爱国与责任意识</th>
            <th colspan="2">法律与环保意识</th>
            <th colspan="6">基本职业素质</th>
            <th colspan="2">企业文化与创新精神</th>
        </tr>
        <tr>
            <th>姓名</th>
            <th>
                <div>基本身体情况</div>
            </th>
            <th>
                <div>体育特长能力</div>
            </th>
            <th>
                <div>艺术审美</div>
            </th>
            <th>
                <div>爱好特长</div>
            </th>
            <th>
                <div>心理健康</div>
            </th>
            <th>
                <div>自我调节</div>
            </th>
            <th>
                <div>自信自强、诚实守信</div>
            </th>
            <th>
                <div>文明素养、个人行为规范</div>
            </th>
            <th>
                <div>爱国意识</div>
            </th>
            <th>
                <div>责任心及服务意识</div>
            </th>
            <th>
                <div>法律意识</div>
            </th>
            <th>
                <div>环保意识</div>
            </th>
            <th>
                <div>语言表达能力及口语特长</div>
            </th>
            <th>
                <div>自我管理,自我激励</div>
            </th>
            <th>
                <div>发展规划能力</div>
            </th>
            <th>
                <div>信息技术能力</div>
            </th>
            <th>
                <div>沟通能力</div>
            </th>
            <th>
                <div>团队合作能力</div>
            </th>
            <th>
                <div>企业文化学习</div>
            </th>
            <th>
                <div>创新能力、解决问题能力</div>
            </th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        <tr>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
            <td>www.qipa250.com</td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>
相关推荐
阿伟来咯~28 分钟前
记录学习react的一些内容
javascript·学习·react.js
吕彬-前端33 分钟前
使用vite+react+ts+Ant Design开发后台管理项目(五)
前端·javascript·react.js
学前端的小朱36 分钟前
Redux的简介及其在React中的应用
前端·javascript·react.js·redux·store
guai_guai_guai1 小时前
uniapp
前端·javascript·vue.js·uni-app
Suckerbin1 小时前
Hms?: 1渗透测试
学习·安全·网络安全
水豚AI课代表1 小时前
分析报告、调研报告、工作方案等的提示词
大数据·人工智能·学习·chatgpt·aigc
聪明的墨菲特i1 小时前
Python爬虫学习
爬虫·python·学习
Diamond技术流1 小时前
从0开始学习Linux——网络配置
linux·运维·网络·学习·安全·centos
斑布斑布1 小时前
【linux学习2】linux基本命令行操作总结
linux·运维·服务器·学习
bysking2 小时前
【前端-组件】定义行分组的表格表单实现-bysking
前端·react.js