J
JJ
I have a vertically long TABLE that I need to be scrollable. For this,
currently I put it in a DIV and use that DIV as the scroller. i.e.:
<div style="height:500px;overflow-y:auto">
<table>
<thead>
<tr><th>header1</th><th>header2</th><th>header3</th></tr>
</thead>
<tbody>
<tr><td>data1 col1</td><td>data1 col2</td><td>data1 col3</td></tr>
<tr><td>data2 col1</td><td>data2 col2</td><td>data2 col3</td></tr>
<tr>
<td>this column can be multiple lines. also variable width</td>
<td>this one always in one line. fixed width</td>
<td>this one always in one line. fixed width</td>
</tr>
<!-- etc. -->
</tbody>
</table>
</div>
This works, but the disadvantage is that, the header row can get out of view
when the table is scrolled. So I want to make the header row sticky like
Windows Explorer's Detail view.
I thought of assigning "overfow-y:auto" style to TBODY, but it's not
applicable since that style is for block/inline-block elements only. But if
I use "display:block" on the TBODY, the table layout is messed up.
So how can I make the header row sticky?
If possible, without using JavaScript at all.
currently I put it in a DIV and use that DIV as the scroller. i.e.:
<div style="height:500px;overflow-y:auto">
<table>
<thead>
<tr><th>header1</th><th>header2</th><th>header3</th></tr>
</thead>
<tbody>
<tr><td>data1 col1</td><td>data1 col2</td><td>data1 col3</td></tr>
<tr><td>data2 col1</td><td>data2 col2</td><td>data2 col3</td></tr>
<tr>
<td>this column can be multiple lines. also variable width</td>
<td>this one always in one line. fixed width</td>
<td>this one always in one line. fixed width</td>
</tr>
<!-- etc. -->
</tbody>
</table>
</div>
This works, but the disadvantage is that, the header row can get out of view
when the table is scrolled. So I want to make the header row sticky like
Windows Explorer's Detail view.
I thought of assigning "overfow-y:auto" style to TBODY, but it's not
applicable since that style is for block/inline-block elements only. But if
I use "display:block" on the TBODY, the table layout is messed up.
So how can I make the header row sticky?
If possible, without using JavaScript at all.