原生table表头固定,内容滚动

HTML:

<div style="width: 1200px;margin: 0 auto;">
        <div class="table-head">
            <table>
                <colgroup>
                    <col style="width: 100px;" />
                    <col />
                </colgroup>
                <thead>
                    <tr>
                        <th style=" width:140px">单元1</th>
                        <th style=" width:330px">单元2</th>
                        <th style=" width:250px">单元3</th>
                        <th style=" width:155px">单元4</th>
                        <th style=" width:155px">单元5</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="table-body">
            <table>
                <colgroup>
                    <col style="width: 100px;" />
                    <col />
                </colgroup>
                <tbody>
                    <tr>
                        <td style=" width:140px">测试1</td>
                        <td style=" width:330px">测试1</td>
                        <td style=" width:250px">测试1</td>
                        <td style=" width:155px">测试1</td>
                        <td style=" width:155px">测试1</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

css:

.table-head {
            padding-right: 4px;
            background-color: #e7e7e7;
            color: #000;
        }

        .table-body {
            width: 100%;
            height: 300px;
            overflow-y: scroll;
            border-bottom: 1px solid #c0bebe;
        }

        .table-head table,
        .table-body table {
            width: 100%;
            border-collapse: collapse;
            padding-right: 10px;
        }

        table tr,
        th,
        td {
            height: 40px;
            line-height: 40px;
            text-align: center;
            border: 1px solid #c0bebe;
            color: #808080;
        }
        th{color: #686868;}
        .table-body::-webkit-scrollbar {
            width: 4px;
            /*height: 4px;*/
        }

        .table-body::-webkit-scrollbar-thumb {
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            background: rgba(0, 0, 0, 0.2);
        }

        .table-body::-webkit-scrollbar-track {
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            border-radius: 0;
            background: rgba(0, 0, 0, 0.1);
        }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值