I have a simple 2-column layout with a footer that clears both the right and left div in my markup. My problem is that I can't get the footer to stay at the bottom of the page in all browsers. It works if the content pushes the footer down, but that's not always the case.
Update:
It's not working properly in Firefox. I'm seeing a strip of background color below the footer when there's not enough content on the page to push the footer all the way down to the bottom of the browser window. Unfortunately, this is the default state of the page.
For this question many of the answers I have seen are clunky, hard to implement and inefficient so I thought I'd take a shot at it and come up with my own solution which is just a tiny bit of css and html
this works by setting the height of the footer and then using css calc to work out the minimum height the page can be with the footer still at the bottom, hope this helps some people :)
An old thread I know, but if you are looking for a responsive solution, this jQuery addition will help:
Full guide can be found here: https://pixeldesigns.co.uk/blog/responsive-jquery-sticky-footer/
I have created a very simple library https://github.com/ravinderpayal/FooterJS
It is very simple in use. After including library, just call this line of code.
Footers can be dynamically changed by recalling above function with different parameter/id.
Note:- You haven't to alter or add any CSS. Library is dynamic which implies that even if screen is resized after loading page it will reset the position of footer. I have created this library, because CSS solves the problem for a while but when size of display changes significantly,from desktop to tablet or vice versa, they either overlap the content or they no longer remains sticky.
Another solution is CSS Media Queries, but you have to manually write different CSS styles for different size of screens while this library does its work automatically and is supported by all basic JavaScript supporting browser.
Edit CSS solution:
Now, if the height of display is more than your content length, we will make footer fixed to bottom and if not, it will automatically appear in very end of display as you need to scroll to view this.
And, it seems a better solution than JavaScript/library one.
Try putting a container div (with overflow:auto) around the content and sidebar.
If that doesn't work, do you have any screenshots or example links where the footer isn't displayed properly?
Since the Grid solution hasn't been presented yet, here it is, with just two declarations for the parent element, if we take the
height: 100%
andmargin: 0
for granted:align-content: space-between
I have myself struggled with this sometimes and I always found that the solution with all those div's within each other was a messy solution. I just messed around with it a bit, and I personally found out that this works and it certainly is one of the simplest ways:
What I like about this is that no extra HTML needs to be applied. You can simply add this CSS and then write your HTML as whenever