给表格加上横向、纵向滚动条并对滚动条进行美化

本文demo基于vue开发,可以根据自己的框架整理,本demo满足以下几点

1、表格横向纵向都有滚动条;

2、滚动条美化;

3、固定列设置,本demo固定列举例为第一列;

<template>
    <div class="container">
        <table>
            <thead>
            <tr>
                <th>序号</th>
                <th>标题1标题1标题1标题1标题1</th>
                <th>标题2</th>
                <th>标题3</th>
                <th v-for="i in 100">
                {{ i+i+i }}
                </th>
            </tr>
            </thead>
            <tbody>
                <tr>
                <td>1</td>
                <td>内容1</td>
                <td>内容2</td>
                <td>内容3</td>
                <td v-for="d in 100">
                {{ d+d+d }}
                </td>
            </tr>
            <tr v-for="(item , index) in 30">
                <td>{{index+2}}</td>
                <td>内容1内容1内容1内容1内容1内容1内容1内容1内容1</td>
                <td>内容2</td>
                <td>内容3</td>
                <td v-for="d in 100">
                {{ d+d+d }}
                </td>
            </tr>
            </tbody>
        </table>
    </div>

</template>
<script>
 
export default {
    data () {
        return {
        }
    },
    created () {
        
    },
    mounted() {
    },
    methods: {
    }
}
</script>
<style lang="scss" scoped>
.container {
    width: 80%;
    height: 362px;
    position: relative;
    // position: absolute;
    // top: 50%;
    // left: 50%;
    // transform: translate(-50%, -50%);
    overflow: auto;
    &::-webkit-scrollbar {
        height: 8px;
        width: 8px;
    }
    &::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.3);
        border-radius: 5px;
    }
    &::-webkit-scrollbar-track {
        background-color: #fff;
    }
    table{
        table-layout:fixed;
        border: none;
        border-collapse: collapse;
        background: white;
        text-align: center;
        thead{
            tr{
                color: white;
                height: 56px;
                th{
                    min-width: 100px;
                    position:-webkit-sticky; 
                    position:sticky;
                    top:0;
                    z-index: 3;
                    background: #fff !important;
                    font-size: 14px !important;
                    color: #222222 !important;
                    font-weight: bold;
                    padding: 12px 8px !important;
                    white-space: nowrap;
                }
                th:nth-of-type(1) {
                    background-color: #F4F4F4;
                    left:0;
                    z-index:4;
                }
            }
        }
        tbody{
            tr{
                height:30px;
                color: #333;
                &:nth-child(2n-1){
                    background: #F4F4F4 !important;
                }
                td{
                    min-width: 100px;
                    position:-webkit-sticky;
                    position:sticky;
                    white-space: nowrap;
                }
                td:nth-of-type(1){
                    background-color: #F4F4F4;
                    left: 0;
                    z-index:3;
                }
            }
        }
    }
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值