学习使用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>
相关推荐
永乐春秋8 分钟前
WEB攻防-通用漏洞&文件上传&js验证&mime&user.ini&语言特性
前端
鸽鸽程序猿9 分钟前
【前端】CSS
前端·css
ggdpzhk11 分钟前
VUE:基于MVVN的前端js框架
前端·javascript·vue.js
学不会•2 小时前
css数据不固定情况下,循环加不同背景颜色
前端·javascript·html
活宝小娜5 小时前
vue不刷新浏览器更新页面的方法
前端·javascript·vue.js
程序视点5 小时前
【Vue3新工具】Pinia.js:提升开发效率,更轻量、更高效的状态管理方案!
前端·javascript·vue.js·typescript·vue·ecmascript
coldriversnow5 小时前
在Vue中,vue document.onkeydown 无效
前端·javascript·vue.js
我开心就好o5 小时前
uniapp点左上角返回键, 重复来回跳转的问题 解决方案
前端·javascript·uni-app
开心工作室_kaic6 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic
java·开发语言·前端
刚刚好ā6 小时前
js作用域超全介绍--全局作用域、局部作用、块级作用域
前端·javascript·vue.js·vue