...

View Full Version : help with absolute positioning footer



tempest4000
11-11-2009, 05:52 PM
I cannot get the footer to sit at the bottom of the page when I use absolute positioning. I need the #main to stretch to whatever the content height and the footer to sit underneath. Can anyone help?


html, body {height:100%;}

#container {
width: 900px;
position: absolute;
top: 0px;
left: 50%;
margin-left: -450px;
}

#header {
width: 900px;
height: 105px;
position: absolute;
left:0;
top: 0;
}

#main {
position: absolute;
left:0;
top: 105px;
}

#footer {
position:absolute;
bottom:0;
border: 1px solid yellow;
}

Excavator
11-11-2009, 06:08 PM
Hello tempest4000,
There's no real need for absolute positioning in your layout, not yet anyway. Have a look at the pitfalls of absolute positioning (http://www.tyssendesign.com.au/articles/css/absolute-positioning-pitfalls/).

Here it is just flowing naturally instead of using ap -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
height:100%;
font: 100.1% "Comic Sans MS";
background: #FC6;
}
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
#container {
width: 900px;
margin: 30px auto 0; /*centers and moves #container down 30px*/
background: #999;
font-size: 0.8em;
}
#header {
height: 105px;
background: #0F0; /*just for testing*/
}
#main {background: #ccc;}
#footer {
height: 105px;
border: 1px solid yellow;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
header
</div>
<div id="main">
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
<!--end main--></div>
<div id="footer">
footer
</div>
<!--end container--></div>
</body>
</html>

If you're looking for a full-height layout you will not get satisfactory results from an absolute positioned footer. Here is a demo of a very good solution http://nopeople.com/CSS/full-height-layout/index.html
View the source to see how it's coded.

tempest4000
11-11-2009, 06:40 PM
Thanks but I had my website site up like that originally until I realised I needed absolute positioning for quite a few elements. The css gets quite complicated and what I have posted is just the main structure.

Does anyone know of any way I can get this to work?

you_know_zo
11-12-2009, 09:41 AM
I recently had a similar problem, although I wasn't using absolute positioning... but this may work for you... I tried to find the article where I found it, but it seems to have disappeared!!

I had a three column layout, and I wanted to stretch the menu column to the same height as the content, and then the footer to sit underneath... which sounds like the same problem you're having...

I put this into the CSS for the menu:


padding-bottom:2000px;
margin-bottom:-2000px;

this in the CSS for the footer:


clear:both;

and this in the CSS for the container:


overflow:hidden;

It's a bit of a messy solution, but it works in all the browsers I've tested it in. Let me know if that helps :)

Excavator
11-12-2009, 03:33 PM
If you're looking for a full-height layout you will not get satisfactory results from an absolute positioned footer. Here is a demo of a very good solution http://nopeople.com/CSS/full-height-layout/index.html
View the source to see how it's coded.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum