views:

83

answers:

3

I want to have a header DIV and a footer DIV always displayed on my web page, regardless of when you scroll down the page.

How do I accomplish this using only CSS (without IFRAMES)

For example:

<div id=header>Always display on top, regardless if you have scrolled down the page</div>
<div id=main_content>...</div>
<div id=footer>Always display on the bottom</div>
+1  A: 

If you can avoid IE 6 then you can use position: fixed.

Something like

<style type="text/css">
    #header { position: fixed; top: 0px; }
    #main_content { height: 1200px; }
    #footer { position: fixed; bottom: 0px; }
</style>
<div id=header>
   Always display on top, regardless if you have scrolled down the page
</div>
<div id=main_content>...</div>
<div id=footer>
    Always display on the bottom
</div>

See A Better Fixed Positioning for Internet Explorer 6

rahul
Along with `top:0;` for the header and `bottom:0;` for the footer.
Brendan Long
A: 
#header { position: fixed; }
#footer { position: fixed; }

But please don't use this. Your users will hate you and leave the site.

Coronatus
A: 
#header{
left:0;
top:0;
height:100px;
width:100%;
position:fixed;
z-index:2;
background:grey;
}
#main_content{
margin-top:100px;
margin-bottom:100px;
height:1000px;
}
#footer{
bottom:0;
left:0;
height:100px;
width:100%;
position:fixed;
z-index:2;
background:grey;
}
s_hewitt