I'm trying to get my table a fixed height - I'll eventually use overflow to scroll. But my height is being ignored.
CSS:
table {
height: 20px;
}
HTML:
<table>
<tr>
<td>
hello
......
I'm trying to get my table a fixed height - I'll eventually use overflow to scroll. But my height is being ignored.
CSS:
table {
height: 20px;
}
HTML:
<table>
<tr>
<td>
hello
......
https://jsfiddle.net/hop061md/
Use display:inline-block
on table.
table {
max-height: 20px;
display: inline-block;
overflow: auto;
background: red;
}
<table>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
</table>
The overflow
property works to the block
elements only...And table
default display property is display:table
...
So I think setting table
to display:block
will be not a good idea...
So Just wrap your table
into a div
and then apply height
and overflow:auto
Stack Snippet
div {
height: 50px;
overflow: auto;
}
table {
border-collapse: collapse;
font: 13px Verdana;
}
td {
border: 1px solid #ccc;
padding: 3px 10px;
}
<div>
<table>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
<tr>
<td>
hello
</td>
</tr>
</table>
</div>