elementui table 默认带滚动条 导致 表头不对齐问题

当页面加载数据,数据条数太多,导致table出现滚动条,应该是 dom渲染问题,table默认加载没有滚动条.数据多 异步加载导致如下问题,问题出在哪,出在 图二 红框 请自行跟图一对比一下!!!
解决方案:
在这里插入图片描述
src->styles->index.scss 或者 APP.vue下 添加 如下 样式,缺一不可! 之前网上搜 直说 写上面的就行,但是 根本不好使!这么写,强行覆盖滚动条样式,width=滚动条宽度 就ok了!

// 全局设置
body .el-table th.gutter {
  display: table-cell !important;
}
.el-table {
  th.gutter,
  colgroup.gutter {
    display: block !important;
    width: 6px !important
  }
}
::-webkit-scrollbar {
  width: 6px
}

在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要实现table下的tbody滚动条与thead对齐的效果,可以使用以下方法: 1. 将thead与tbody分开放到两个div中,一个div用于显示thead,另一个div用于显示tbody,这两个div都设置为相同的宽度。 2. 对于tbody所在的div,设置overflow属性为auto,这样当tbody内容超出div的高度时,会自动生成滚动条。 3. 针对每一列,可以通过设置不同的宽度来实现不均等。 具体实现代码如下: HTML代码: ``` <div class="table-container"> <div class="thead-container"> <table> <thead> <tr> <th style="width: 100px;">列1</th> <th style="width: 200px;">列2</th> <th style="width: 150px;">列3</th> <th style="width: 50px;">列4</th> </tr> </thead> </table> </div> <div class="tbody-container"> <table> <tbody> <tr> <td style="width: 100px;">内容1</td> <td style="width: 200px;">内容2</td> <td style="width: 150px;">内容3</td> <td style="width: 50px;">内容4</td> </tr> <tr> <td style="width: 100px;">内容1</td> <td style="width: 200px;">内容2</td> <td style="width: 150px;">内容3</td> <td style="width: 50px;">内容4</td> </tr> <!-- more rows --> </tbody> </table> </div> </div> ``` CSS代码: ``` .table-container { display: flex; flex-direction: column; height: 300px; /* 设置表格高度 */ } .thead-container { overflow: hidden; height: 30px; /* 设置表头高度 */ } .thead-container table { width: 100%; /* 与tbody-container同宽 */ border-collapse: collapse; } .tbody-container { flex: 1; overflow: auto; /* 当tbody内容超出div高度时,显示滚动条 */ } .tbody-container table { width: 100%; /* 与thead-container同宽 */ border-collapse: collapse; } .tbody-container td, .tbody-container th { white-space: nowrap; /* 防止文字换行 */ } ``` 通过以上代码,就可以实现thead与tbody对齐,并且每一列可以不均等的效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值