Sticky footer
It'd be good if Bootstrap supported sticky footers (floats to bottom of page for pages shorter than the browser window).
Agreed
You can make the footer sticky pretty easily using this method: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
Thanks - will take a look at this tonight.. ! :)
-----Original Message----- From: dvanderbeek [mailto:[email protected]] Sent: Wednesday, 28 September 2011 11:01 PM To: Peter Kneale Subject: Re: [bootstrap] Sticky footer (#306)
You can make the footer sticky pretty easily using this method: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
Reply to this email directly or view it on GitHub: https://github.com/twitter/bootstrap/issues/306#issuecomment-2224629
Going to skip on this one—easy to add on with a limited about of CSS. If we get any more requests, we'll revisit.
It would be nice if this was just part of the css ... maybe similar to container and container-fluid ... something like footer and footer-sticky.
+1
Just add position: fixed; left: 0; right: 0; bottom: 0; to your "bottom-bar" and put some padding-bottom on your main container so your content doesn't get hidden underneath it.
I did it on a project recently (that's unfortunately not live yet, so can't demonstrate) and it really isn't too much trouble. Bootstrap is meant to be a starting point; you are allowed to add your own CSS on top!
EDIT: A more complete example, just to demonstrate how simple it is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
<style>
.container[role="main"] {
padding-bottom: 60px;
}
.bottombar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div class="container" role="main">
<!-- your content -->
</div>
<div class="bottom-bar">
<div class="bottombar-inner">
<div class="container">
<ul class="nav">
<li><a href="#">Link 1</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
@martinbean thanks :)
Wouldn't this method cause the footer to always be visible? The method I suggested pushes the footer to the bottom if there is a small amount of content on the page, but if there is a lot of content the footer gets pushed "below the fold" so to speak. That way it isn't floating on top if the page scrolls.
Sorry, I thought the issue was you wanted a static bottom bar like there is a static top bar.
Even then, it isn't that much code to add to achieve a sticky footer as @markdotto says. Why not write your own styles for it so it only applies if your <body> tag has a class of .footer-sticky? That way you can toggle the behaviour on or off with just the single class name.
That's a good idea. I will try that at some point.
I used a combination of the technique found in http://jsdo.it/Bakey/bootstrap-sticky-footer and http://ryanfait.com/resources/footer-stick-to-bottom-of-page/.
For my html/haml I had something like:
%body
.topbar
.main
.container
# content here
.push
%footer.footer
For the scss it was:
html, body {
height: 100%;
}
.main {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -1*($topbar-height + $footer-height - 10px);
}
.main > .container {
padding-top: $topbar-height;
}
footer.footer {
height: $footer-height;
background: #eee;
}
.push {
height: $footer-height + $topbar-height;
}
I think the topbar made this a pain to implement because of the $topbar-height padding. I also have a trial-and-error 10px in the margin calculation of the .main style.
It would be really nice to get an official or clean implementation that works with and without the topbar.
in agreement, sticky footer would be killer addition.
FWIW, I've spent a few hours trying to make an existing sticky footer implementation work with bootstrap (ryanfait's one) and it's being completely thrown off by bootstrap.
I also have tried and handful of different combinations of the above techniques with no simple solution. It seems to me that at this point it is clearly complex enough to build into the core and have it fully supported. Just my opinion
What exactly are the problems people are facing trying to implement a sticky footer with Bootstrap? I haven't try myself yet but don't see why it would be so difficult?
@martinbean: I think people in this thread are looking for two different things
- Some want the footer to be properly "sticky" at all time, kinda like facebook's footer. Somewhere that chat and notifications can sit.
- Others want it to only be sticky when the content is smaller than the page, and to move down otherwise. This would be used to create a company footer, like the github one at the bottom of this page.
ryanfait's, listed above, does the latter, but is broken by bootstrap. I couldn't make it work - I think because of the 100% in the body, and the offsets and margins used by bootstrap. (I'm sorry I have no more details, I've forgotten it).
@dteoh's implementation above, I think, does the former, and I got it to work with a bit of hacking after hours of trying to make ryanfait's one work. But this is not ideal - it covers content, which is not what my company footer should do.
For a fixed footer (i.e. Facebook's) you just need to replicate the styles used in .topbar but obviously set bottom: 0; instead of top: 0;. I've done it before in a project.
For a 'sticky' footer (i.e. Ryan Fait's) I'm not sure without having a crack at it myself. I'll see if I can find some time in the next couple of days to have a go.
I have a version of the fluid layout working with a sticky footer in my fork of the bootstrap repo. It's in examples/sticky.html and requires the sticky.css file in addition to bootstrap.css. Does anyone see anything that could be improved there? Since the body needs padding: 0px for the sticky footer solution to work, I added a class to the container that includes padding to push the content down below the fixed topbar.
https://github.com/dvanderbeek/bootstrap/blob/master/examples/sticky-footer.html
@dvanderbeek I played around with your solution and it seems to be working nicely with and without the topbar.