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

本文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
    评论
在 Python 中,可以使用 tkinter 模块来创建 GUI 应用程序。如果你想要在 GUI 应用程序中添加文本控件,并为其添加横向纵向滚动条,可以按照以下步骤进行操作: 1. 导入 tkinter 模块: ``` import tkinter as tk ``` 2. 创建主窗口并设置窗口标题: ``` root = tk.Tk() root.title("Scrollable Text") ``` 3. 创建文本控件并添加文本内容: ``` text = tk.Text(root, wrap="none") text.insert("end", "Your text here") ``` 4. 创建横向滚动条并将其与文本控件绑定: ``` xscrollbar = tk.Scrollbar(root, orient="horizontal", command=text.xview) text.configure(xscrollcommand=xscrollbar.set) ``` 5. 创建纵向滚动条并将其与文本控件绑定: ``` yscrollbar = tk.Scrollbar(root, orient="vertical", command=text.yview) text.configure(yscrollcommand=yscrollbar.set) ``` 6. 将文本控件、横向滚动条纵向滚动条添加到主窗口中: ``` text.pack(side="left", fill="both", expand=True) xscrollbar.pack(side="bottom", fill="x") yscrollbar.pack(side="right", fill="y") ``` 7. 运行主窗口: ``` root.mainloop() ``` 完整代码示例: ``` import tkinter as tk root = tk.Tk() root.title("Scrollable Text") text = tk.Text(root, wrap="none") text.insert("end", "Your text here") xscrollbar = tk.Scrollbar(root, orient="horizontal", command=text.xview) text.configure(xscrollcommand=xscrollbar.set) yscrollbar = tk.Scrollbar(root, orient="vertical", command=text.yview) text.configure(yscrollcommand=yscrollbar.set) text.pack(side="left", fill="both", expand=True) xscrollbar.pack(side="bottom", fill="x") yscrollbar.pack(side="right", fill="y") root.mainloop() ``` 这样就可以创建一个带有横向纵向滚动条的文本控件了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值