Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Footer at the bottom in fluid layout

I have a fluid layout but as a consequence, when there is no enough content in the page, my footer keeps moving up as in this example.

enter image description here

A popular solution to keep the footer at the bottom of the page is using position: fixed or position: absolute, however, when I do that, the content can collide with the footer on resizing (you can see what I mean here. Try to resize your window to the point in which the text is hiding behind the footer).

enter image description here

So how can I get a footer at the bottom but moving accordingly with the rest of the page in a fluid layout?

Thanks!

like image 754
Robert Smith Avatar asked Mar 09 '12 23:03

Robert Smith


People also ask

How do I make a footer at the bottom?

< div id = "footer" >This is a footer. This stays at the bottom of the page.

What is a bottom footer?

The website footer is the section of content at the very bottom of a web page. It typically contains a copyright notice, link to a privacy policy, sitemap, logo, contact information, social media icons, and an email sign-up form.

How do I fix the footer at the bottom when the 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.

What position should a footer be?

A footer is the last element on the page. At a minimum it is at the bottom of the viewport, or lower if the page content is taller than the viewport. Simple, right? ? When working with dynamic content that includes a footer, a problem sometimes occurs where the content on a page is not enough to fill it.


2 Answers

There's a CSS way to do this. Or at least there's one that works for all the browsers I support (back to IE7).

I use the negative margin-top trick to stick the footer to the bottom of the page. That DIV is wrapped around the entire page contents instead of just the header, which suffices for most people. Let's say that DIV has a class "everything-but-the-footer". I then force the page to be at least window height. Full version that works on most browsers:

html, body, .everything-but-the-footer {
    height: 100%;
}

.everything-but-the-footer {
    margin-top: -21px; // footer height + border * -1
    min-height: 100%
}

.footer {
    height: 20px;
    border-top-width: 1px;
}

.header {
    padding-top: 21px; // footer height + border
}

Note that the JSFiddle technique listed in the comments doesn't work on IE at all and on Chrome doesn't solve the stated problem (footer and contents overlapping).

like image 72
Jason Avatar answered Sep 22 '22 23:09

Jason


I dont think there is a proper solution using only CSS, however you can try giving your main content area a min-height. Set it to a safe height and if the content takes more space, it would expand accordingly.

Try this and see whether you are looking for something similar

http://jsfiddle.net/blackpla9ue/wCM7v/1/

What this does is, if the content area is smaller than your viewport, it positions the footer to the bottom of the viewport, and if its larger than the viewport it just stays at the bottom of the content like it is supposed to. An event is added to the resize event so even once you resize your browser, it would position itself appropriately.

like image 34
Malitta N Avatar answered Sep 21 '22 23:09

Malitta N