Search code examples
htmlcsstwitter-bootstrap-3footersticky

Bootstrap sticky footer with image


What I am trying to achieve is a page with a sticky footer, which is a vector island.

  1. The island is always at the bottom of the page, but when the browser height is too small it invokes vertical scrolling.

  2. Behind the island is a sunburst that then falls behind all the page content. This is quite big, about 1417px high. This doesn't affect vertical scrolling though.

Here is what I have so far and I've been stuck for hours! Any help would be appreciated.

<!DOCTYPE html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="IE=edge" http-equiv="X-UA-Compatible">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="description">
  <meta content="" name="author">
  <link href="../../docs-assets/ico/favicon.png" rel="shortcut icon">

  <title>Sticky Footer Template for Bootstrap</title><!-- Latest compiled and minified CSS -->
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <style type="text/css">

  html,
  body {
  height: 100%;
  background-color: #6ec8e4;
  }

  #wrap {
  min-height: 100%;
  height: auto;
  }


  .testBox{
  height: 300px;
  width: 100%;
  background: red;
  margin: 20px 0;
  }

  .footer-image-container {
  margin: 0 auto;
  position: absolute;
  width: 100%;
  height: 1417px;
  }

  .footer-image {
  position: absolute;
  bottom: 0;
  z-index: -1;
  }

  </style>
</head>

<body>
  <!-- Wrap all page content here -->

  <div id="wrap">
    <!-- Begin page content -->

    <div class="container">
      <div class="page-header">
        <h1>Sticky footer</h1>
      </div>

      <div class="row">
        <div class="testBox"></div>
      </div>

      <div class="row">
        <div class="testBox"></div>
      </div>

      <div id="footer">
        <div class="footer-image-container"><img class="img-responsive footer-image" src="http://i.imgur.com/wSNrfJD.png">
        <img class="img-responsive footer-image" src="http://i.imgur.com/alDv0tE.png"></div>
      </div>
    </div>
  </div><!-- Bootstrap core JavaScript
  ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>


Solution

  • It would be better to use the images as background images in css:

    see https://jsfiddle.net/6t9vxq1o/1/

    .body{
        height:100%;
        background: url(http://i.imgur.com/wSNrfJD.png) no-repeat center bottom;   
    }
    #wrap{
        background:url(http://i.imgur.com/alDv0tE.png) no-repeat center bottom;   
    }
    

    This way the images will be always on bottom, the sunburst behind the content, and the grass behind the footer