Page and background not centering (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


ncriptide -> Page and background not centering (11/24/2007 10:54:12)

I'm a beginner CSS coder, so I'm sure I've done something extremely stupid:

I have a wrapper div that is 850px wide. I have set margins to: 0 auto;

It looks fine on a Mac running Firefox or Explorer, but when viewed on IE 5 or 6 on a PC, the background image is off and the site is flush left - not centered.

My header div is 800px wide and centered, and my main content dive is 800px and centered, so the background image of the wrapper will show on sides and top evenly.

Here's the url: http://www.hudsontrailers.com

Here's the css:

body {
background-color:#003300;
font-family:Palantino "Times New Roman", Times, serif;
font-size: 1em;
text-align:left;
}

#wrapper {
background-image:url(../images/bkgnd.jpg);
background-attachment:fixed;
width: 850px;
height;
margin: 25px auto;
padding:25px 0;
}

#header {
background-color:#003300;
border-top:medium solid #FFFFFF;
border-right: medium solid #FFFFFF;
border-left: medium solid #FFFFFF;
width: 800px;
margin: 0 auto;
padding:0;

}
#main {
clear:both;
background-image:url(../images/images/main_bkgnd.jpg);
width:800px;
margin:0 auto;
padding:0;
border-left: medium solid #FFFFFF;
border-right: medium solid #FFFFFF;
border-bottom: medium solid #FFFFFF;
}

Any help would be greatly appreciated.




Tailslide -> RE: Page and background not centering (11/24/2007 14:09:43)

I can't check at the moment but if you haven't used a DOCTYPE then IE6 will be behaving like IE 5 (it'll be in quirks mode) and one of the side effects of this is that it will be using older rules for styling. You should really add a DOCTYPE (haven't got the link here but google "fix your site with the right doctype" to get a list).

You will also need to replace the "text align="left"' in the body rule with "text-align="center". Now add "text-align="left"" to the wrapper div. The centralising rule on the body will centralise everything for the older browsers and the text-align left on the wrapper will normalise the text again.




ncriptide -> RE: Page and background not centering (11/24/2007 17:41:49)

Problem solved!

Had to add the following to the wrapper div:

position:absolute;
left: 50%;
margin-left: -425px;

Along with your suggestion of:

body { text-align:center; }
#wrapper { text-align:left; }

Everything is smelling like roses on IE 5 & 6 now . . . thanks for all your help!!!!!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
3.076172E-02