I have a website with a footer that I want to stick to the bottom of the page. In my case, there’s also a sidebar, making the structure a tad more complex than just main and footer inside the html body.
The typical recommendation to make the body min-height: 100vh, and the main content flex-grow: 1 does not work in my case.
How can I make the footer stick to the bottom in the code sample below? I am hoping for a flexbox-based solution.
body {
}
#outer-container {
display: flex;
}
#inner-container {
flex-grow: 1;
display: flex;
flex-direction: column;
}
footer {
}
<body>
<div id="outer-container">
<aside>ASIDE</aside>
<div id="inner-container">
<main>MAIN</main>
<footer>FOOTER</footer>
</div>
</div>
</body>
2
Answers
You need to add
display: flex;
to the parent andflex-grow: 1;
to the child. Also, addmin-height: 100vh;
to the#inner-container
.See the snippet below.
By default the height is undefined and will be calculated to
fit-content
. YOu need to add amin-height: 100vh
to the container to utilize the entire screen as a minimum. Then the easiest way to push the footer to the bottom is by giving in amargin-top: auto