bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Sticky footer

Open hugovincent opened this issue 15 years ago • 263 comments

It'd be good if Bootstrap supported sticky footers (floats to bottom of page for pages shorter than the browser window).

hugovincent avatar Sep 25 '11 22:09 hugovincent

Agreed

pkneale-ce avatar Sep 26 '11 10:09 pkneale-ce

You can make the footer sticky pretty easily using this method: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

dvanderbeek avatar Sep 28 '11 13:09 dvanderbeek

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

pkneale-ce avatar Sep 29 '11 06:09 pkneale-ce

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.

mdo avatar Oct 04 '11 06:10 mdo

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.

mattruma avatar Nov 14 '11 22:11 mattruma

+1

JanDupal avatar Nov 25 '11 12:11 JanDupal

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 avatar Nov 25 '11 12:11 martinbean

@martinbean thanks :)

JanDupal avatar Nov 25 '11 15:11 JanDupal

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.

dvanderbeek avatar Nov 25 '11 15:11 dvanderbeek

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.

martinbean avatar Nov 25 '11 15:11 martinbean

That's a good idea. I will try that at some point.

dvanderbeek avatar Nov 25 '11 15:11 dvanderbeek

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.

dteoh avatar Nov 26 '11 07:11 dteoh

in agreement, sticky footer would be killer addition.

dewde avatar Dec 14 '11 07:12 dewde

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.

pbiggar avatar Dec 14 '11 08:12 pbiggar

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

gregmoser avatar Dec 21 '11 21:12 gregmoser

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 avatar Dec 21 '11 21:12 martinbean

@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.

pbiggar avatar Dec 21 '11 21:12 pbiggar

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.

martinbean avatar Dec 21 '11 21:12 martinbean

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 avatar Dec 22 '11 00:12 dvanderbeek

@dvanderbeek I played around with your solution and it seems to be working nicely with and without the topbar.

dteoh avatar Dec 22 '11 00:12 dteoh