element-plus固定最后两行数据不动

在el-table中添加class=‘fixed-nth-last-child’

<el-table
  class="fixed-nth-last-child"
></el-table>

css样式如下:

为了让表格呈现滚动效果,必须设定table-layout:fixed 并且给与表格宽度

要注意的是当position : sticky应用于table,只能作用于<th>和<td>,并且一定要定义目标位置 left / right / top / bottom 才会出现固定效果!

// 修改倒数第二行的样式
:deep .fixed-nth-last-child tr:nth-last-child(2) {
  position: sticky; // 固定表格则需要使用到 position : sticky 的设定
  table-layout: fixed;
  bottom: 36px; // 设置的列表行高
  z-index: 2; // 和列表滚动条保持一致,高了会遮盖滚动条
}
// 修改倒数第一行的样式
:deep .fixed-nth-last-child tr:nth-last-child(1) {
  position: sticky;
  table-layout: fixed;
  bottom: 0;
  z-index: 2;
}

 

posted @ 2023-03-01 16:42  代码改变世界是吧  阅读(663)  评论(0)    收藏  举报