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>
相关推荐
Ai-_Man22 分钟前
您您这可以把Microsofat Copilot的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。AI导出鸭
javascript·人工智能·ai·小程序·电脑·copilot
特创数字科技1 小时前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用
前端
IT_陈寒2 小时前
Vue的v-if和v-for混用居然是个天坑
前端·人工智能·后端
天衍四九-2 小时前
【无标题】
前端·spring boot·mysql·nginx·docker
广州华水科技2 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度
前端
xcyxiner2 小时前
DicomViewer24 修复编译bug(window test 失败)
前端·qt
linux_cfan3 小时前
videojs v10 源代码系列解读:34 · `createComposition`:类型安全的冲突检测
前端·安全
Bruce_Liuxiaowei4 小时前
网页版 DeepSeek “harness desktop“ WebGL 上下文创建失败排查实录
开发语言·javascript·webgl
utmhikari4 小时前
【AI原生】借助AI之力优化个人博客前端样式
前端·css·hexo·next·个人博客·ai-native·vibe coding