table 滚动时固定表头

表格内容过多时,仅滚动数据,表头不动

css 复制代码
  table {
    height: 100%;
    overflow: auto;
    table-layout: fixed;
    display: block;

    & > thead {
      position: sticky;
      top: 0;
      left: 0;
      right: 0;
      display: table;
      width: 100%;
      table-layout: fixed;
      z-index: 1;
    }

    & > tbody {
      display: table;
      width: 100%;
      table-layout: fixed;
    }
  }

表格html:

html 复制代码
<table>
  <thead>
    <tr>
      <th width="50px"></th>
      <!--表头-->
    </tr>
  </thead>
  <tbody>
    <tr v-if="tableData.length">
      <td width="50px"></td>
      <!--表内容-->
    </tr>
    <tr v-else>
      <td colspan="5" style="text-align: center;">暂无数据</td>
    </tr>
  </tbody>
</table>
相关推荐
世界哪有真情3 分钟前
3月12日最新!Cursor无限续杯
前端·后端·cursor
Archie_IT11 分钟前
使用DeepSeek+蓝耘快速设计网页简易版《我的世界》小游戏
前端·人工智能·大模型·html·aigc·deepseek
柒@宝儿姐16 分钟前
Vue动态修改页面的 title 浏览器页签名称
前端·javascript·vue.js
颜酱21 分钟前
后台系统从零搭建(三)—— 具体页面之菜单管理和角色管理
前端·javascript·react.js
OpenTiny社区26 分钟前
Node.js 技术原理分析系列5——理解 Node.js 中的 ABI 稳定
前端·node.js
the_one37 分钟前
手写 AJAX:从零实现一个简洁的异步请求函数
前端·javascript
xulihang39 分钟前
vCard名片二维码在前端的生成与扫描
前端·javascript·图像识别
zhaoyong6311 小时前
利用微软的 HTML 应用程序宿主程序的攻击
前端·microsoft·html
只会写Bug的程序员1 小时前
面试之《原型与原型链》
前端·面试
1 小时前
📌面试答不上的问题-HTTP缓存
前端·面试