My goal is to show the header
and div
in the current window height, leaving the footer
hidden until the user scrolls.
I am trying to figure out a way to make div
have a minimum height, so that the footer starts to show. However, when I do this the footer
ends up going overtop of my div
.
How can I give my div
a minimum height but still make sure that the content doesn’t overlap each other?
As you can see, footer goes over top of div.
body, html {
height:100%;
}
section {
display: flex;
flex-direction: column;
height: 100%;
}
header {
border:1px solid red;
}
footer {
border: 1px solid blue;
background-color:blue;
}
div {
background-color:#eee;
flex: 1;
min-height:200px;
}
<section>
<header>header</header>
<div>content</div>
</section>
<footer>footer</footer>
3
Answers
I’m confused by your question and what you’re trying to achieve.
You start saying you want the footer to be hidden until the user scrolls, which is what is already happening.
Then you say you want the start of the footer to show but without overlapping the div? In that case just make the height of the
<section>
less than 100%, otherwise there is no way to view the footer without it overlapping yourdiv
content.I have tried a few things that came to my mind, but haven’t found a solution that contains the 200px min-height for the
div
. However, as a workaround, you could apply a min-height tobody
, with a value that approximately equals 200px plus the height of header and footer. I used 240px in my snippet below, but you can adjust that value as needed. At least that way you don’t get that overlap of the footer.