Prevent table body from going beyond visible height of screen then add scrollbar
I have a table on a page. Sometimes it will have 10 rows, and other times it will have over 100 rows. I'd like the table to go all the way down to the bottom of the screen if there are enough rows but not past that. I want it to add a scrollbar for just the tbody if there are enough rows to go beyond the height of the screen. I don't want a scrollbar for the page just the tbody if necessary. I also want the thead to always be visible at the top.
Here is a jsFiddle http://jsfiddle.net/65o2bxfy/ This is mostly what I want, but I'd like it to fill to the bottom and always have the thead visible.
I also have to use table-layout: fixed on my table so that column widths are the right size.
In other places I have seen this code, but it won't work for me because I don't know the height in advance just that I want it to fill up the screen.
table
height: 300px;
display: block;
overflow-y: scroll;
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
Thanks!
html css css-tables
add a comment |
I have a table on a page. Sometimes it will have 10 rows, and other times it will have over 100 rows. I'd like the table to go all the way down to the bottom of the screen if there are enough rows but not past that. I want it to add a scrollbar for just the tbody if there are enough rows to go beyond the height of the screen. I don't want a scrollbar for the page just the tbody if necessary. I also want the thead to always be visible at the top.
Here is a jsFiddle http://jsfiddle.net/65o2bxfy/ This is mostly what I want, but I'd like it to fill to the bottom and always have the thead visible.
I also have to use table-layout: fixed on my table so that column widths are the right size.
In other places I have seen this code, but it won't work for me because I don't know the height in advance just that I want it to fill up the screen.
table
height: 300px;
display: block;
overflow-y: scroll;
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
Thanks!
html css css-tables
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
height: 100vh;
Or if you have margin paddings, a header etc.height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39
add a comment |
I have a table on a page. Sometimes it will have 10 rows, and other times it will have over 100 rows. I'd like the table to go all the way down to the bottom of the screen if there are enough rows but not past that. I want it to add a scrollbar for just the tbody if there are enough rows to go beyond the height of the screen. I don't want a scrollbar for the page just the tbody if necessary. I also want the thead to always be visible at the top.
Here is a jsFiddle http://jsfiddle.net/65o2bxfy/ This is mostly what I want, but I'd like it to fill to the bottom and always have the thead visible.
I also have to use table-layout: fixed on my table so that column widths are the right size.
In other places I have seen this code, but it won't work for me because I don't know the height in advance just that I want it to fill up the screen.
table
height: 300px;
display: block;
overflow-y: scroll;
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
Thanks!
html css css-tables
I have a table on a page. Sometimes it will have 10 rows, and other times it will have over 100 rows. I'd like the table to go all the way down to the bottom of the screen if there are enough rows but not past that. I want it to add a scrollbar for just the tbody if there are enough rows to go beyond the height of the screen. I don't want a scrollbar for the page just the tbody if necessary. I also want the thead to always be visible at the top.
Here is a jsFiddle http://jsfiddle.net/65o2bxfy/ This is mostly what I want, but I'd like it to fill to the bottom and always have the thead visible.
I also have to use table-layout: fixed on my table so that column widths are the right size.
In other places I have seen this code, but it won't work for me because I don't know the height in advance just that I want it to fill up the screen.
table
height: 300px;
display: block;
overflow-y: scroll;
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
Thanks!
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
table
height: 300px;
display: block;
overflow-y: scroll;
<div>
<div></div>
<div><table>
<thead>
<tr>
<th>COL 1</th>
<th>COL 2</th>
<th>COL 3</th>
<th>COL 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
<tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr> <tr>
<td>Text col 1</td>
<td>Text col 2</td>
<td>Text col 3</td>
<td>Text col 4</td>
</tr>
</tbody>
</table></div>
</div>
html css css-tables
html css css-tables
edited Nov 12 '18 at 17:52
justDan
1,0991718
1,0991718
asked Nov 12 '18 at 16:14
t_m27
489
489
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
height: 100vh;
Or if you have margin paddings, a header etc.height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39
add a comment |
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
height: 100vh;
Or if you have margin paddings, a header etc.height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
height: 100vh;
Or if you have margin paddings, a header etc. height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
height: 100vh;
Or if you have margin paddings, a header etc. height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39
add a comment |
1 Answer
1
active
oldest
votes
Use CSS viewport units. 1 vh
connotes 1/100th of the height of your viewport (same with vw
for width). min-height: 100vh
should do the trick.
table
min-height: 100vh;
display: block;
overflow-y: scroll;
Browser support is good for it too https://caniuse.com/#feat=viewport-units
However, this solution only works if you have no other elements on your page and you're happy for it to sit at 100% tall. You could use calc()
to offset the difference from other elements heights but then you're relying on those elements to have fixed heights.
If you're able to provide me more context as to where you want your tables to sit on your page I may be able to help you out a bit better.
To keep your the header of your table sticky set the th
cells with a position of sticky
.
thead th
position: sticky;
top: 0;
Browser support is more sparse for that but good enough for production.
https://caniuse.com/#search=sticky
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266077%2fprevent-table-body-from-going-beyond-visible-height-of-screen-then-add-scrollbar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use CSS viewport units. 1 vh
connotes 1/100th of the height of your viewport (same with vw
for width). min-height: 100vh
should do the trick.
table
min-height: 100vh;
display: block;
overflow-y: scroll;
Browser support is good for it too https://caniuse.com/#feat=viewport-units
However, this solution only works if you have no other elements on your page and you're happy for it to sit at 100% tall. You could use calc()
to offset the difference from other elements heights but then you're relying on those elements to have fixed heights.
If you're able to provide me more context as to where you want your tables to sit on your page I may be able to help you out a bit better.
To keep your the header of your table sticky set the th
cells with a position of sticky
.
thead th
position: sticky;
top: 0;
Browser support is more sparse for that but good enough for production.
https://caniuse.com/#search=sticky
add a comment |
Use CSS viewport units. 1 vh
connotes 1/100th of the height of your viewport (same with vw
for width). min-height: 100vh
should do the trick.
table
min-height: 100vh;
display: block;
overflow-y: scroll;
Browser support is good for it too https://caniuse.com/#feat=viewport-units
However, this solution only works if you have no other elements on your page and you're happy for it to sit at 100% tall. You could use calc()
to offset the difference from other elements heights but then you're relying on those elements to have fixed heights.
If you're able to provide me more context as to where you want your tables to sit on your page I may be able to help you out a bit better.
To keep your the header of your table sticky set the th
cells with a position of sticky
.
thead th
position: sticky;
top: 0;
Browser support is more sparse for that but good enough for production.
https://caniuse.com/#search=sticky
add a comment |
Use CSS viewport units. 1 vh
connotes 1/100th of the height of your viewport (same with vw
for width). min-height: 100vh
should do the trick.
table
min-height: 100vh;
display: block;
overflow-y: scroll;
Browser support is good for it too https://caniuse.com/#feat=viewport-units
However, this solution only works if you have no other elements on your page and you're happy for it to sit at 100% tall. You could use calc()
to offset the difference from other elements heights but then you're relying on those elements to have fixed heights.
If you're able to provide me more context as to where you want your tables to sit on your page I may be able to help you out a bit better.
To keep your the header of your table sticky set the th
cells with a position of sticky
.
thead th
position: sticky;
top: 0;
Browser support is more sparse for that but good enough for production.
https://caniuse.com/#search=sticky
Use CSS viewport units. 1 vh
connotes 1/100th of the height of your viewport (same with vw
for width). min-height: 100vh
should do the trick.
table
min-height: 100vh;
display: block;
overflow-y: scroll;
Browser support is good for it too https://caniuse.com/#feat=viewport-units
However, this solution only works if you have no other elements on your page and you're happy for it to sit at 100% tall. You could use calc()
to offset the difference from other elements heights but then you're relying on those elements to have fixed heights.
If you're able to provide me more context as to where you want your tables to sit on your page I may be able to help you out a bit better.
To keep your the header of your table sticky set the th
cells with a position of sticky
.
thead th
position: sticky;
top: 0;
Browser support is more sparse for that but good enough for production.
https://caniuse.com/#search=sticky
edited Nov 14 '18 at 13:52
answered Nov 12 '18 at 16:21
Ciaran Wood
335
335
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266077%2fprevent-table-body-from-going-beyond-visible-height-of-screen-then-add-scrollbar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
like this jsfiddle.net/65o2bxfy/2 ?
– Madhawa Priyashantha
Nov 12 '18 at 16:23
height: 100vh;
Or if you have margin paddings, a header etc.height: calc(100vh - 100px);
– Simsteve7
Nov 12 '18 at 16:25
Making the thead stay on top, is not possible using a table. Unless using some javascript (lot's of plugins available).
– Simsteve7
Nov 12 '18 at 16:26
@MadhawaPriyashantha That example doesn't go all the way to the bottom of the screen.
– t_m27
Nov 12 '18 at 16:28
@Simsteve7 The calc(100vh - 100px) is what I was looking for. I just now need to find a way to handle the header if it's not possible using a table.
– t_m27
Nov 12 '18 at 16:39