我的頁面上有標題行,然後在頁面上顯示一個表格。我想要凍結表格的頂行和頂行,並將表格放在可滾動的位置。我的桌子沒有<THEAD>
元素,我也嘗試過使用positon:固定來凍結標題行和表格的頂行,但只有頂行被固定。我怎樣才能凍結標題行? TIA將HTML表格的幾行和最上面的行凍結
代碼:
<div id="topheader">
<h1> This is header line </h1>
</div>
<table ellspacing="0" cellpadding="10" border="1" width="100%" STYLE="empty-cells:show; position:fixed; top:300px;" id="reporttable" >
<tr class="header">
<td align="left">
Field1
</td>
<td align="left">
Field2
</td>
<td align="left">
Field3
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="10" border="1" width="100%" STYLE="empty-cells:show;" id="reporttables">
<tr class="tbody" >
<td>
Data1
</td>
<td>
Data2
</td>
<td>
Data3
</td>
</tr>
</table>
</div>
CSS:
<style>
div.topheader{
position:fixed;
top:200px;
}
</style>
張貼最小示例代碼,使我們可以提供幫助。你也會允許一個javascript解決方案嗎? –
你可以閱讀關於DataTable。我想這可能會幫助你https://www.datatables.net/examples/basic_init/scroll_y.html。 – dinesh
@Abhinav:我也對javascript解決方案開放。 – Ruchi