Forum Moderators: not2easy

Message Too Old, No Replies

CSS 100% Height DIV's tutorial - Reprive for Centered Fixed Width

         

edoky145

12:23 am on May 8, 2007 (gmt 0)

10+ Year Member



Hello,

I found this tutorial on ur website for creating div tags that extend all the way down the page.

[webmasterworld.com...]

However it seems that this only works if the positioning is absolute. For a centered fix width layout this absolute positioning will not work. Does anyone have a suggestion on how you could accomplish this in a different way?

This is what i have so far (it doesn't work)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Fixed Width Centered Layout</title>

<style>
body {
background: #333333;
margin:0;
padding:0;
height:100%; /* this is the key! */
color: #333333;
}

#container {
position:relative;
margin-left:auto;
margin-right:auto;
width: 852px;
height:100%;
background: #999999;
}
</style>
</head>

<body>
<div id="container">
Here is where i want my div tag to go all the way down the page. <br /><br />
Here is where i want my div tag to go all the way down the page. <br /><br />
Here is where i want my div tag to go all the way down the page. <br /><br />

</div>
</body>
</html>

Right now the column only goes as far as my content goes.

Thanks in advance for any suggestions!

sifredi

5:24 am on May 8, 2007 (gmt 0)

10+ Year Member



html {height: 100%;}

body {
background: #333;
height:100%; /* this is the key! */
margin: 0 auto;
width: 852px;
}

#container {
height:100%;
background: #999;
}

Xapti

5:33 am on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you could approximate, but going position;absolute;left:40%;top:0, but that's not too awesome. No real problem with it aside form appearance though.

Weird: (at least to me)
if you set body to position:absolute... it left-aligns the div (and it does stretch all the way down)
position:relative on the body doesn't seem to do anything FYI.

edoky145

4:37 pm on May 8, 2007 (gmt 0)

10+ Year Member



thanks sifredi

that worked like a charm.

Xapti

6:31 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A strange thing is it doesn't work if I put height="100%" in the html tag, only if it's put in the style will it work. (didn't try style="height:100%")

[edited by: Xapti at 6:35 pm (utc) on May 8, 2007]