Search code examples
htmlcsstwitter-bootstrap-3sticky-footer

bootstrap 3: 3 row stick on top and bottom


Sorry for my poor English

I studied bootstrap and try to code the layout like this enter image description here

Grey part is browser window.

  • Row 0 must stick on top(like navigation bar)
  • Row 2 must stick on bottom(like footer)
  • Row 1 is dynamic height depended on the browser window height.

how to present these through CSS?

<div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-md-5 column">
            </div>
            <div class="col-md-2 column">
            </div>
            <div class="col-md-5 column">
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-md-12 column">
            </div>
        </div>
    </div>

Solution

  • Try use this code:

    <html>
      <head>
        <link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
        <script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
        <script data-require="bootstrap@*" data-semver="3.1.1" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    
        <style>
          p{text-align: center;}
          html, body{height:100%;}
          #content{
            min-height:100%;
            height:auto !important;
            height:100%;
            /* Negative indent header and footer by its height */
            margin:-80px auto -60px;
            /* Pad bottom by header and footer height */
            padding:80px 0 60px;
          }
          /* Set the fixed height of the header here */
          #header{height:80px;}
          /* Set the fixed height of the footer here */
          #footer{height:60px;}
        </style>
      </head>
    
      <body>
        <div id="header">
          <div class="container">
            <div class="row">
              <div class="col-xs-12"><p>header</p></div>
            </div>
          </div>
        </div>
    
        <div id="content">
          <div class="container">
            <div class="row">
              <div class="col-xs-5"><p>left column</p></div>
              <div class="col-xs-2"><p>center column</p></div>
              <div class="col-xs-5"><p>right column</p></div>
            </div>
          </div>
        </div>
        <div id="footer">
          <div class="container">
            <div class="row">
              <div class="col-xs-12"><p>footer</p></div>
            </div>
          </div>
        </div>
      </body>
    </html>