html table固定表头 css,使用css固定table表头

本文介绍如何在不使用框架的情况下,利用原生JavaScript解决大数据量表格的显示问题,通过固定表头实现更好的用户体验。代码示例展示了如何创建一个带有滚动条且表头固定的表格,适用于需要展示大量数据的场景。
摘要由CSDN通过智能技术生成

这篇文章上次修改于 202 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

前言

最近有个需求,渲染一个很复杂的table表格,不能用框架实现,使用原生table数据量一大就看不到表头需要固定表头,本篇文章当备份吧

代码

CodePen Demo

.table-container {

width: 50%;

height: 200px;

border: solid 1px #cccccc;

margin: 10px auto;

background: #FFF;

-webkit-transform: translate(-50%, -50%);

transform: translate(-50%, -50%);

position: absolute;

top: 50%;

left: 50%;

padding-top: 50px;

overflow: hidden;

}

.table-container-inner {

overflow-x: hidden;

overflow-y: auto;

height: 100%;

}

.table-header-fixed {

width: 100%;

background: #FFF;

overflow-x: hidden;

overflow-y: auto;

}

th, td, span {

text-align: left;

}

th span {

position: absolute;

top: 0;

width: 100%;

display: block;

line-height: 50px;

border-left: solid 1px #3a84ac;

border-bottom: solid 1px #cccccc;

padding-left: 5px;

margin-left: -5px;

font-weight: 400;

letter-spacing: 1px;

color: #FFF;

background: #549DC5;

}

CSS - Fixed Header With Variable Width Table

First

Second

Third

Forth

FirstSecondThirdForthFirstSecond222222222222222222222222222ThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForthFirstSecondThirdForth
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值