CSS Sticky Footer Implementation Issue

I have some problems for the Sticky Footer to work on my site. If the content is smaller than the window, the footer should remain at the bottom of the window, and the dead space should be filled with a div. I think CSS Sticky Footer does this, but I can't get the "push div" to work to push the content to the end. As you can see, my code is not only the footer of the body.

<body>
  <div id="banner-bg">
    <div id="wrapper">
      <div id="header-bg">
        <!-- header stuff -->
      </div> <!-- end header-bg -->
      <div id="content-bg">
        <div id="content">
          <!-- content stuff -->
        </div> <!-- end content -->
      </div> <!-- end content-bg -->
    </div> <!-- end wrapper -->
  </div> <!-- end banner-bg -->
</body>

body { 
    color:              #00FFFF;
    background-image:   url("Images/img.gif");
    font-size:          1em;
    font-weight:        normal;
    font-family:        verdana;
    text-align:         center;
    padding:            0;
    margin:             0;
}

#banner-bg {
    width:              100%;
    height:             9em;
    background-image:   url("Images/img2.gif"); background-repeat: repeat-x;
    position: absolute; top: 0;
}

#wrapper {
    width:              84em;
    margin-left:        auto; 
    margin-right:       auto;
}

#header-bg {
    height:             16em;
    background-image:   url("Images/header/header-bg.png"); 
}

#content-bg {
    background-image:   url("Images/img3.png"); background-repeat: repeat-y;
}

#content {
    margin-right:       2em; 
    margin-left:        2em;
}

I am confused about where the CSS Sticky Footer code should be used in my case.

Change, this is what I got and what I want to do: alt text http://bayimg.com/image/gacniaacf.jpg

+5
source share
5 answers

HTML . , banner-bg ?

, Sticky Footer , , DIV. , <body> DIV - wrapper footer. , , DIV.

, Sticky Footer , , , , wrapper, .

: , , . "Sticky Footer" cssstickyfooter.com . HTML ( ), , , . , , , .

<html>
<head>
 <style>
* {margin: 0; padding: 0} 
html, body, #wrap {height: 100%}
body > #wrap {height: auto; min-height: 100%}
#main {padding-bottom: 100px}  /* must be same height as the footer */
#footer {position: relative;
  margin-top: -100px; /* negative value of footer height */
    height: 100px;
    clear:both;
}
/* CLEAR FIX*/
.clearfix:after {content: "."; display: block; height: 0;   clear: both; visibility: hidden}
.clearfix {display: inline-block}
/* Hides from IE-mac \*/
* html .clearfix { height: 1%}
.clearfix {display: block}
/* End hide from IE-mac */ 

/* Do not touch styles above - see http://www.cssstickyfooter.com */

body {
  background-image: url("Images/img.gif");
  background: #99CCFF;
  color: #FFF;
  font-size: 13px;
  font-weight: normal;
  font-family: verdana;
  text-align: center;
  overflow: auto;
}

div#banner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 9em;
  background: url("Images/img2.gif") repeat-x;
  background: #000;
}

div#wrap {
  background: #666;
  width: 84em;
  margin-left: auto;
  margin-right: auto;
}

div#header {
  height: 16em;
  padding-top: 9em; /* banner height */
  background: url("Images/header/header-bg.png");
  background: #333; 
}

div#footer {
  background: #000;
  width: 84em;
  margin-left: auto;
  margin-right: auto;
}

 </style>
</head>
<body>
 <div id="banner">Banner</div>
 <div id="wrap">
    <div id="main" class="clearfix">
     <div id="header">Header</div> 
     <div id="content">
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content<br />
     Content
   </div> <!-- end content -->
    </div> <!-- end main -->
 </div>
 <div id="footer">
  Footer
 </div>
</body>
</html>
+5

, ( CSS Sticky Footer), . , :

<html>
<head>
<style type="text/css">
html, body {
    height: 100%;
}
#container {
    height: 100%;
    margin: 0 0 -200px 0;
    position: relative;
}
#footer {
    position: relative;
    height: 200px;  
}

</style>
</head>
<body>

<div id="container">
    <div id="header">Oh Beautiful Header</div>
    <div id="content">Lots of Content</div>
</div>
<div id="footer">Stay Put Little Footer</div>
</body>

, 100% html/body, .

, xHTML, , div " " "" div, ( divs, ).

, IS:

  • 100% - ​​ html body.
  • div, # banner-bg
  • 100px, # banner-bg margin-bottom: -100px
  • # banner-bg, #footer

      html {height: 100%;}

    body { 
        color:                      #00FFFF;
        background-image:   url("Images/img.gif");
        font-size:                  1em;
        font-weight:        normal;
        font-family:        verdana;
        text-align:                 center;
        padding:                    0;
        margin:                     0;
        height: 100%;
    }
    
    #banner-bg {
        width:                      100%;
        height:                     100%;
        background-image:   url("Images/img2.gif"); background-repeat: repeat-x;
        position: relative;
        margin: 0 0 -200px 0;
    }
    
    #wrapper {
        width:                      84em;
        margin-left:        auto; 
        margin-right:       auto;
    }
    
    #header-bg {
        height:                     16em;
        background-image:   url("Images/header/header-bg.png"); 
    }
    
    #content-bg {
            background-image:       url("Images/img3.png"); background-repeat: repeat-y;
    }
    
    #content {
        margin-right:       2em; 
        margin-left:        2em;
    }
    #footer {
        position: relative;
        height: 200px;  
    }
    

:

    <body>
          <div id="banner-bg">
            <div id="wrapper">
              <div id="header-bg">
                <!-- header stuff -->
              </div> <!-- end header-bg -->
              <div id="content-bg">
                <div id="content">
                  <!-- content stuff -->
                </div> <!-- end content -->
              </div> <!-- end content-bg -->
            </div> <!-- end wrapper -->
          </div> <!-- end banner-bg -->
          <div id="footer">
          Footer Content
          </div>
        </body>
</html>
+1

, Sticky Footer , , ... , Javascript . -.

0

, , CSS HTML, / - .

JavaScript, . JS, . jQuery :

JQuery

$(window).resize(function() {

    if ($('body').height() < $(window).height()) {
        $('#footer').addClass('fixed');
    }
    else {
        $('#footer').removeClass('fixed');
    }

}).resize();

CSS

#footer.fixed { position: fixed; bottom: 0; width: 100%; }
0

CSS . .wrapper , .footer .push. ( , ).

CSS:

height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}

HTML. .wrapper .footer div, CSS. div.push, , "" , .

In the HTML body:

          

The content of your site is here.

  <div class="push"></div>
    </div>
    <div class="footer">
        <p>Copyright (c) 2013</p>
    </div>
0
source

All Articles