Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force footer on bottom on pages with little content

Tags:

css

footer

sticky

I have a page with only a couple of lines of content. I want the footer to be pushed to the bottom.

<div id="footer"></div> 

I don't want to use

#footer {     position:fixed;     bottom:0; } 

AKA Sticky Footer

Is this possible without jQuery?

any suggestions?

like image 705
pom4ik Avatar asked May 21 '13 20:05

pom4ik


People also ask

How do I stick footer to the bottom when page content is less?

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. I will explain few ways to keep or stick the footer to the bottom of the page if there is not enough content.

How do I push footer below content?

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 force the footer to the bottom of the page in CSS?

First wrap all of your main content in a div element and give it a class of “wrapper” (or call it whatever you want). Now, make sure you give your footer a height. Then use the calc() function to set the height of your wrapper equal to the height of the viewport (display), minus the height of the footer.

How do you get the footer to stay at the bottom of a Web page?

Keep the footer at the bottom by using Flexbox Make sure that you are wrapping everything in a <div> or any other block-level element with the following CSS styles: min-height:100vh; display:flex; flex-direction:column; justify-content:space-between; .


1 Answers

This Flexbox solution is neater and far easier to implement:

HTML

<body>   <div class="content">     content   </div>   <footer class="footer"></footer> </body> 

CSS

html, body {   height: 100%; } body {   display: flex;   flex-direction: column; } .content {   flex: 1 0 auto; } .footer {   flex-shrink: 0; } 

Just ensure you wrap the necessary divs inside the body.

like image 120
Chidozie Nnachor Avatar answered Sep 23 '22 03:09

Chidozie Nnachor