加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

html Table 表头固定的实现

发布时间:2020-05-12 08:39:56 所属栏目:MySql教程 来源:站长网
导读:div class=wrapboxdiv class=table-headtabletheadth width=10%合同号/thth width=30%签约客户/thth width=20%发布客户/thth width=10%合同状态/thth width=30%选定条件的发布周期额度/th/thead/table/divdiv class=table-bodytabletbody id=tbody/tbody/t

<div class="wrapbox"> <div class="table-head"> <table> <thead> <th width="10%">合同号</th> <th width="30%">签约客户</th> <th width="20%">发布客户</th> <th width="10%">合同状态</th> <th width="30%">选定条件的发布周期额度</th> </thead> </table> </div> <div class="table-body"> <table> <tbody id="tbody"> </tbody> </table> </div> </div>

看看css

*{ padding:0; margin:0; } th{ border:1px solid #e6e6e6; line-height: 5vh; color:#666666; font-size: 16px; } table { border-collapse: collapse; width: 100%; } td { padding:5px; border:1px solid #e6e6e6; font-size: 14px; } .table-head{padding-right:17px;background-color:rgb(207, 231, 179);color:#000;height:5vh;} .table-body{width:100%; height:94vh;overflow-y:scroll;} .table-head table,.table-body table{width:100%;} .table-body table tr:nth-child(2n+1){background-color:#f2f2f2;} .table-body table tr:hover { background-color:rgb(240, 249, 228); transition: .2s; }

点击看效果

其实关键之处在于

1、使用了colgroup标签,来对上下两个表格的列宽进行了定义,让他们保持一致。

2、上边的div .table-head添加了样式padding-right:17px,这个宽度是为了保证跟下边的div .table-body的滚动条保持一致,同时下边的表格.table-body添加了样式overflow-y:scroll;

只要保证上述两点的话,你也可以做出固定表头的表格来,同时不会发生上下的列不对齐的问题,屡试不爽!

html Table 表头固定的实现

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读