Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky footer, along with scrolling div without specific height

I'd like a page with a sticky footer, and I'd like the content above it to be scroll-able, while maintaining the stickiness of the footer. But I don't want to hard-code the height of the content area, but instead would like its height to be all the available height except for the height of the footer.

In the long run I would even like for the height of the scroll-able content area to be re-sizable if the window is re-sized, but I'm getting ahead of myself. I'm presuming I'm going to need a combination of CSS and Javascript to acheive this, that CSS alone cannot acheive it?

I've researched of course and have found the CSS overflow property, but my CSS in general is not very good :( Below is some CSS/HTML I've cobbled together based on ryanfait.com's sticky footer tutorial, if somebody can give me some advice using this as a starting point. Bear in mind, I will need straight Javascript, not jQuery, as this will be used in a custom browser (http://tkhtml.tcl.tk/hv3.html). My Javascript unlike my CSS though is pretty good, so an answer combining specific CSS suggestions with general Javascript suggestions (which I will then flesh out), would be ideal.

<html>
    <head>
<style>
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
</style>
    </head>
    <body>
        <div class="wrapper">
            <p>Your website content here.</p>
            <div class="push"></div>
        </div>
        <div class="footer">
            <p>Copyright (c) 2008</p>
        </div>
    </body>
</html>

EDIT: What I've attempted based on first two answers:

I've made the following modifications to the CSS based on parts of the two answers received so far:

<style>
* {
  margin: 0;
}
html, body {
  height: 100%;
}
.wrapper {
  min-height: 100%;
  height: auto !important;
  height: 100%;
  margin: 0 auto -4em;
  overflow-y: scroll;
}
.footer {
  bottom: 0;
  height: 4em;
  position: fixed;
}
</style>

What this gives me in Chrome are two scrollbars, one very faint, but the more prominent one still allowing content that overflows (maybe I'm using the term incorrectly?) outside of the wrapper area, and over the top (or under the bottom) of the footer, plus outside the entire body. Thanks for help making progress but I still need quite a bit of help. Here's a link to a screenshot of what I'm seeing; I used http://www.ipsum-generator.com/ to generate all the content.

http://dl.dropbox.com/u/44728447/dynamic_wrapper_sticky_footer.JPG

like image 322
Dexygen Avatar asked Oct 12 '11 23:10

Dexygen


2 Answers

html, body {
    height:100%;
    overflow:hidden;
}
.wrapper {
    overflow-y:scroll;
    height: 90%;
}
.footer {
    position:static;
    bottom: 0;
    height: 10%;
}

Demo: http://jsfiddle.net/vfSM3/

like image 74
AlienWebguy Avatar answered Nov 08 '22 17:11

AlienWebguy


On the footer div use position fixed and bottom 0 like:

.footer {
  bottom: 0;
  height: 4em;
  position: fixed;
}
like image 31
Gadget Blaster Avatar answered Nov 08 '22 18:11

Gadget Blaster