Table表格固定表头和第一列、内容可滚动

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <title></title>
    <meta charset="gbk" />
    <style type="text/css">
        .fixContainer {
            width: 600px;
            height: 500px;
            padding: 0;
            box-sizing: border-box;
        }
        .fixContainer tr:nth-of-type(odd) {
            background: #E7F2FF;
        }
        .fixContainer table {
            width: 100%;
            text-align: center;
            border-collapse: collapse;
            border-spacing: 0;
        }
        .fixContainer table td {
            word-break: break-all;word-wrap: break-word;
        }
        /*可以美化一下滚动条*/
        #right_div_2::-webkit-scrollbar {
            /*滚动条整体样式*/
            width: 4px;
            height: 4px;
        }
 
        #right_div_2::-webkit-scrollbar-thumb {
            /*滚动条里面小方块*/
            border-radius: 5px;
            box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            background: rgba(0, 0, 0, 0.2);
        }
 
        #right_div_2::-webkit-scrollbar-track {
            /*滚动条里面轨道*/
            box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            border-radius: 0;
            background: rgba(0, 0, 0, 0.1);
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
 
    <script type="text/javascript">
        $(function () {
            //生成表格内容
            let htmlLeft = '';
            let htmlRight = '';
            for (let i = 1; i <= 17; i++) {
                htmlLeft += '<tr>';
                htmlLeft += '<td style="color: #384967;height: 50px;width: 80px;line-height: 50px;overflow: hidden;text-align: center;">' + i + '</td>';
                htmlLeft += '</tr>';
            }
            for (let i = 1; i <= 17; i++) {
                htmlRight += '<tr>';
                htmlRight += '<td style="color: #384967;height: 50px;width: 80px;line-height: 50px;overflow: hidden;text-align: center;">A</td>';
                htmlRight += '<td style="color: #384967;height: 50px;width: 80px;line-height: 50px;overflow: hidden;text-align: center;">100</td>';
                htmlRight += '<td style="color: #384967;height: 50px;width: 80px;line-height: 50px;overflow: hidden;text-align: center;">500</td>';
                htmlRight += '<td style="color: #384967;height: 50px;width: 80px;line-height: 50px;overflow: hidden;text-align: center;">1</td>';
                htmlRight += '</tr>';
            }
            $('#left_table_2').html(htmlLeft);
            $('#right_table_2').html(htmlRight);
            //滚动
            $('#right_div_2').on('scroll', function () {
                let top = $(this).scrollTop();
                let left = $(this).scrollLeft();
                $('#left_div_2').scrollTop(top);
                $('#right_div_1').scrollLeft(left);
            })
        });
    </script>
</head>
 
<body>
    <div class="fixContainer">
        <div style="width: 80px;float: left;">
            <div id="left_div_1" style=" width: 100%;">
                <table>
                    <tr>
                        <th style="color: #1E304F;background-color: #F3F8FF;">编号</th>
                    </tr>
                </table>
            </div>
            <div id="left_div_2" style="width: 100%;height: 250px;overflow: hidden;">
                <table id="left_table_2" style="margin-bottom: 4px;"></table>
            </div>
        </div>
        
        <div style="float: left;width: 500px;">
            <div id="right_div_1" style="width: 100%; overflow: hidden;">
                <table id="right_table_1" style="width: 800px;">
                    <tr>
                        <th style="color: #1E304F;background-color: #F3F8FF;">测试列一</th>
                        <th style="color: #1E304F;background-color: #F3F8FF;">测试列二</th>
                        <th style="color: #1E304F;background-color: #F3F8FF;">测试列三</th>
                        <th style="color: #1E304F;background-color: #F3F8FF;">测试列四</th>
                    </tr>
                </table>
            </div>
            <div id="right_div_2" style="width: 100%;height: 250px;overflow: auto;">
                <table id="right_table_2" style="width: 800px;overflow: auto;"></table>
            </div>
        </div>
    </div>
</body>
 
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兰舟轻帆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值