Coder Perfect

Sticky Footer for Twitter Bootstrap 3

Problem

I’ve been using the Twitter Bootstrap framework for quite some time, and they just released version 3!

I’m having difficulties getting the sticky footer to stick to the bottom of the page; I’ve tried using the beginning template from the Twitter Bootstrap website, but no luck; any suggestions?

Asked by Brad Fletcher

Solution #1

Simply add the navbar-fixed-bottom class to your footer.

<div class="footer navbar-fixed-bottom">

Answered by Jon

Solution #2

There is no need to put div id=”push”>/div> in the official Boostrap3 sticky footer example, and the CSS is simpler.

The official example’s CSS is as follows:

/* Sticky footer styles
-------------------------------------------------- */

html,
body {
  height: 100%;
  /* The html and body elements cannot have any padding or margin. */
}

/* Wrapper for page content to push down footer */
#wrap {
  min-height: 100%;
  height: auto;
  /* Negative indent footer by its height */
  margin: 0 auto -60px;
  /* Pad bottom by footer height */
  padding: 0 0 60px;
}

/* Set the fixed height of the footer here */
#footer {
  height: 60px;
  background-color: #f5f5f5;
}

as well as the necessary HTML:

<body>

    <!-- Wrap all page content here -->
    <div id="wrap">

      <!-- Begin page content -->
      <div class="container">

      </div>
    </div>

    <div id="footer">
      <div class="container">

      </div>
    </div>
</body>

The source code for this css may be found in the sticky-footer example.

<!-- Custom styles for this template -->
<link href="sticky-footer.css" rel="stylesheet">

Sticky-footer.css (https://getbootstrap.com/docs/3.4/examples/sticky-footer.css)

Answered by tkymtk

Solution #3

Here’s a method for adding a sticky footer to your website that doesn’t require any more CSS or Javascript beyond what’s currently included in Bootstrap and won’t interfere with your present footer.

Here’s an example: Sticky Footer Made Simple

Simply copy and paste this into your code. There’s no bother, no fuss.

<div class="navbar navbar-default navbar-fixed-bottom">
    <div class="container">
      <p class="navbar-text pull-left">© 2014 - Site Built By Mr. M.
           <a href="http://tinyurl.com/tbvalid" target="_blank" >HTML 5 Validation</a>
      </p>

      <a href="http://youtu.be/zJahlKPCL9g" class="navbar-btn btn-danger btn pull-right">
      <span class="glyphicon glyphicon-star"></span>&nbsp; Subscribe on YouTube</a>
    </div>
</div>

Answered by anataliocs

Solution #4

Remember to add the push div before closing the wrap div, in addition to the CSS you just added.

HTML’s core structure is as follows:

<div id="wrap"> 
    page content here 
    <div id="push"></div>
</div> <!-- end wrap -->

<div id="footer">
    footer content here
</div> <!-- end footer -->

Live view Edit view

Answered by David Taiaroa

Solution #5

Because they’re continually improving it, here’s the simplified Sticky Footer code as of today:

HTML

<!DOCTYPE html>
<html lang="en">
  <head></head>

  <body>

    <!-- Fixed navbar -->
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <!-- Begin page content -->
    <div class="container">
      <div class="page-header">
        <h1>Sticky footer with fixed navbar</h1>
      </div>
      <p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
      <p>Back to <a href="../sticky-footer">the default sticky footer</a> minus the navbar.</p>
    </div>

    <footer>
      <div class="container">
        <p class="text-muted">Place sticky footer content here.</p>
      </div>
    </footer>

  </body>
</html>

CSS

/* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
}
footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  background-color: #f5f5f5;
}

Answered by Leniel Maccaferri

Post is based on https://stackoverflow.com/questions/17966140/twitter-bootstrap-3-sticky-footer