Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a footer to the bottom of page when content is short or missing?

Tags:

html

css

I have a page with an outer div that wraps a header, content and footer div. I want the footer div to hug the bottom of the browser, even when the content div is not tall enough to fill the viewable area (i.e. there's no scrolling).

like image 823
Will Curran Avatar asked Jan 01 '11 21:01

Will Curran


People also ask

How do I stick footer to bottom of page if not enough content?

Quick answer: Add “display:flex; flex-direction:column; min-height:100vh;” to body or appropriate layout body element, then add “flex:1;” to content wrapper element/section.

How do you force a footer to the bottom of the page?

To make a footer fixed at the bottom of the webpage, you could use position: fixed. < div id = "footer" >This is a footer. This stays at the bottom of the page.

How do I keep the footer at the bottom of the page with dynamic height?

If you wrap the content in a tag and set the margin-bottom value to the same as the footer-height, you would be able to read the text that the footer was originally covering.


1 Answers

Your issue can be easily fixed by using flexbox. Just wrap your .container and your .footer in a flex container with a min-height: 100vh, switch the direction to column so that they stack on top of each other, and justify the content with space between so that footer will move to the bottom.

.flex-wrapper {   display: flex;   min-height: 100vh;   flex-direction: column;   justify-content: space-between; }
<div class="flex-wrapper">   <div class="container">The content</div>   <div class="footer">The Footer</div> </div>
like image 149
Luke Flournoy Avatar answered Sep 23 '22 22:09

Luke Flournoy