The code below is a simple page that expects an scrollable content (called red
) on top of a fixed footer (called green
):
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.red {
background-color: red;
overflow-y: scroll;
}
.green {
background-color: green;
overflow-y: none;
}
<div class="container">
<div class="red">
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
<p>Line</p>
</div>
<div class="green">
<p>FOOTER LINE 1</p>
<p>FOOTER LINE 2</p>
</div>
</div>
The code is simple, but my green
footer is scrolling together with the content.
How can I fix my CSS code to keep my green
footer fixed on the bottom of the screen?
[EDIT] The suggested duplicate does not solve my problem, as it requires me to specify a footer height. I need the footer to have its height according to its content, and the remaining space on top to show the scrollable content.