本文介紹了html Table 表頭固定的實現(xiàn),分享給大家,具體如下:
<div class="wrapbox"> <div class="table-head"> <table> <thead> <th width="10%">合同號</th> <th width="30%">簽約客戶</th> <th width="20%">發(fā)布客戶</th> <th width="10%">合同狀態(tài)</th> <th width="30%">選定條件的發(fā)布周期額度</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;
只要保證上述兩點的話,你也可以做出固定表頭的表格來,同時不會發(fā)生上下的列不對齊的問題,屢試不爽!
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
標簽:蘇州 紅河 甘南 文山 營口 萍鄉(xiāng) 咸陽 惠州
巨人網(wǎng)絡通訊聲明:本文標題《html Table 表頭固定的實現(xiàn)》,本文關鍵詞 html,Table,表頭,固,定的,實現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。