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>
相关推荐
code_YuJun21 分钟前
corepack 作用
前端
千寻girling21 分钟前
Koa.js 教程 | 一份不可多得的 Node.js 的 Web 框架 Koa.js 教程
前端·后端·面试
全栈前端老曹23 分钟前
【MongoDB】Node.js 集成 —— Mongoose ORM、Schema 设计、Model 操作
前端·javascript·数据库·mongodb·node.js·nosql·全栈
code_YuJun23 分钟前
pnpm-workspace.yaml
前端
天才熊猫君26 分钟前
“破案”笔记:iframe动态加载内容后,打印功能为何失灵?
前端
五月君_43 分钟前
炸裂!Claude Opus 4.6 与 GPT-5.3 同日发布:前端人的“自动驾驶“时刻到了?
前端·gpt
Mr Xu_1 小时前
前端开发中CSS代码的优化与复用:从公共样式提取到CSS变量的最佳实践
前端·css
低代码布道师1 小时前
Next.js 16 全栈实战(一):从零打造“教培管家”系统——环境与脚手架搭建
开发语言·javascript·ecmascript
鹏北海-RemHusband1 小时前
从零到一:基于 micro-app 的企业级微前端模板完整实现指南
前端·微服务·架构
LYFlied1 小时前
AI大时代下前端跨端解决方案的现状与演进路径
前端·人工智能