Forum Moderators: not2easy

Message Too Old, No Replies

Can't center page using wrapper take 2

Absolute positioning inside main wrapper causing problems?

         

webgoddess

8:10 pm on Nov 26, 2007 (gmt 0)

10+ Year Member



I have a wrapper div that I thought the other divs would be positioned to absolutely. But something is keeping the page from being centered. Help!

Here is the CSS:
body {
margin: 0;
padding: 0;
text-align: center;
width: 800px;
font: small/17px Verdana, Arial, Helvetica, sans-serif;
}
#wrapper {
text-align: left;
width: 800px;
margin-right: auto;
margin-left: auto;
}
#bluebg {
position:absolute;
left:0px;
top:167px;
width:800px;
background: #336699;
margin: 0px;
}
#whitecontent {
background: #FFFFFF;
left:10px;
top: 0px;
width:740px;
margin: 0px 10px;
padding: 0px 20px 20px;
}
#header {
position:absolute;
left:0px;
top:0px;
width:798px;
height:136px;
z-index:1;
}
#tabmenu {
position:absolute;
left:238px;
top:145px;
width:560px;
height:24px;
z-index:2;
}

Here is the HTML:
<body topmargin="0">
<div id="wrapper">
<div id="header"><img src="images/main3.gif" width="800" height="169" /></div>

<div id="tabmenu">
<script src="images/ltbluetop.js"></script>
</div>

<div id="bluebg">
<div id="whitecontent">
</div>
<div><img src="images/bu004119a.gif" width="800" height="22" /></div>
</div>
</div>

</body>

Thanks for any help you can give.

webgoddess

8:35 pm on Nov 26, 2007 (gmt 0)

10+ Year Member



Sorry, forgot doc type:
<!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">

jessejump

9:07 pm on Nov 26, 2007 (gmt 0)

10+ Year Member



Absolutely positioned divs are positioned to the page

Xapti

12:52 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Webgoddess is generally wrong, I'll elaborate after this -

I don't see the necessity of giving a width for body, so I'd remove that.
Your wrapper does not have what's called "containing block" status.
Generically speaking, to give make an element be containing box, you should set position:relative to the element. This will make it so that positioning like position:absolute are positioned relative to that element. With no containing block, absolute positioning defaults to the document root. More information can be found through the following link, which specifies containing block behaviour, as well as other W3C rendering standards:
[w3.org...]

webgoddess

1:33 am on Nov 27, 2007 (gmt 0)

10+ Year Member



Xapti,
I am eternally grateful to you. I copied the code from a book on CSS on how to center a page and the position:relative was not included. That little detail was the fix. Thank you so much!

Xapti

12:22 am on Nov 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well for the page to be centered, that is not needed. It's when you want to use absolute positioning, and have the elements positioned relative to it's container.