I have a unique layout challenge with two stacked divs inside a container div. The container div has height: 100%
, and the bottom inner-div has a dynamic height that changes based on its content. My goal is to make the top div take up the remaining space in the container, so that the bottom div appears fixed at the bottom of the viewport.
<div class="container" style="height: 100%">
<div class="my-height-should-be-the-remainder-of-the-container" style="overflow: scroll">
<p>My content should be able to scroll if there's too much to display</p>
</div>
<div class="my-height-should-take-priority-over-the-top-div">
<p>The height of this div should adjust dynamically based on its content</p>
<p>As such, the content should not overflow outside the div</p>
</div>
</div>
I've attempted using display: table
with the inner divs set as display: table-row
, but I'm struggling to make the top div respect the overflow: scroll
; it ends up pushing the bottom div out of view.
While I'm aware that I could use position: fixed
on the bottom div and adjust the padding-bottom
of the top div dynamically with JavaScript, I am hoping to find a CSS-only solution, preferably one that doesn't involve flexbox.
Any suggestions or help would be greatly appreciated. Thank you!