項(xiàng)目中設(shè)計(jì)的報(bào)表table設(shè)計(jì)的列數(shù)相對(duì)過(guò)多,當(dāng)拖動(dòng)下方的滾動(dòng)條時(shí)無(wú)法對(duì)應(yīng)表頭所對(duì)應(yīng)的列,因此在網(wǎng)上搜索了好一段日子,最后在網(wǎng)上找到了一些參考資料,然后總結(jié)歸納出兼容行列合并的固定表頭demo。
多瀏覽器沒(méi)有做太多測(cè)試,在ie6中已測(cè)試通過(guò)。
功能期待了很久今天終于找到解決的方式,總結(jié)到j(luò)avaeye中方便日后查閱。實(shí)現(xiàn)方式可能還有更好的,希望有大牛路過(guò),給我留點(diǎn)更好的實(shí)現(xiàn)例子作日后交流之用。
以下是相關(guān)的css
<style type=”text/css”>
<!–
body,table, td, a {font:9pt;}
/*重點(diǎn):固定行頭樣式*/
.scrollRowThead{position: relative; left: expression(this.parentElement.parentElement.parentElement.parentElement.scrollLeft);z-index:0;}
/*重點(diǎn):固定表頭樣式*/
.scrollColThead {position: relative;top: expression(this.parentElement.parentElement.parentElement.scrollTop);z-index:2;}
/*行列交叉的地方*/
.scrollCR { z-index:3;}
/*div外框*/
.scrollDiv {height:200px;clear: both; border: 1px solid #EEEEEE;OVERFLOW: scroll;width: 320px; }
/*行頭居中*/
.scrollColThead td,.scrollColThead th{ text-align: center ;}
/*行頭列頭背景*/
.scrollRowThead,.scrollColThead td,.scrollColThead th{background-color:EEEEEE;}
/*表格的線*/
.scrolltable{border-bottom:1px solid #CCCCCC; border-right:1px solid #CCCCCC; }
/*單元格的線等*/
.scrolltable td,.scrollTable th{border-left: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 5px; }
.scrollTable thead th{background-color:#EEEEEE;font-weight:bold;position:relative;}
–>
</style>
以下是HTML
<h1>利用CSS代碼讓Table產(chǎn)生固定表頭</h1>
<div id=”scrollDiv” class=”scrollDiv” >
<table border=”0″ cellpadding=”3″ cellspacing=”0″ width=”500″ class=”scrollTable”>
<thead>
<tr class=”scrollColThead” >
<th class=”scrollRowThead scrollCR” > </th>
<th colspan=”2″>列頭</th>
<th colspan=”2″>列頭</th>
<th rowspan=”2″>列頭</th>
</tr>
<tr class=”scrollColThead” >
<th class=”scrollRowThead scrollCR” >h1</th>
<th >h2</th>
<th >h3</th>
<th >h4</th>
<th >h5</th>
</tr>
</thead>
<tr>
<td class=”scrollRowThead” >
<input type=”checkbox” name=”checkbox” value=”checkbox”>
a</td>
<td>單元格2</td>
<td>單元格3</td>
<td>單元格4</td>
新聞熱點(diǎn)
疑難解答
圖片精選