I'm having trouble getting a footer to stick to the bottom of a scrollable block element. It only works if the content (table in this case) is greater than the container height. How do I always get the the footer to stick to the bottom?
I tried using position: absolute
instead, but that stays fixed when the user scrolls.
.container {
position: relative;
overflow-y: scroll;
height: 150px;
display: block;
border: solid 1px black;
}
.footer {
position: sticky;
right: 0;
bottom: 0;
float: right;
background-color: lightblue;
}
<div class="container">
<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>
<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 class="footer">Footer</div>
</div>
<br/>
<div class="container">
<table>
<tr><td>Hello</td></tr>
<tr><td>Hello</td></tr>
<tr><td>Hello</td></tr>
</table>
<div class="footer">Footer</div>
</div>