tags:

views:

52

answers:

3

Ok, lets see if i can explain this. My page content has a width of 960px. It is centered in another div that has a width of 1426px (#siteWrap).

#siteWrap{
margin:0px auto;
width:1426px;
background: url(../images/bg.jpg) no-repeat ;
}

What i need to find out is how to get #siteWrap to center on a page regardless of screen resolutions. Most of my visitors are on a 1024x768 screen resolution. When i test this page on that resolution i am forced to scroll left to right to get to the site content.

Any help would be appreciated.

+2  A: 

Just set

width: 100%;

and the margin: 0 auto; should be set on your content div, not on this one.

stephenhay
I don't think this is exactly what the OP is asking for. This would cause the background to position top-left, rather than being centered on the page, which would mean the content would not be positioned on the center of the background.
Travis
No, it wouldn't. The div would be 100%, with the content div of 960px being inside of it, centered with margin: 0 auto;. How did reach that conclusion?
stephenhay
Sorry, I guess that wasn't completely clear. Your solution would work, as long as you added background-position:center; Otherwise, by default the background image would be positioned in the top-left of your 100% width div. Without that, the content would be positioned in the center of the page, but the background would be top-left, so they wouldn't align properly in the middle.
Travis
(I just assumed that background-position:center was obvious. I shouldn't assume :)
stephenhay
A: 

When a container overflows horizontally, the browsers natural reaction is to dock it to the left side of the screen. I think it should be doing this. To get around it, you can use Javascript to center your container element by calculating the necessary offsets based on screen/viewport resolution.

Josh Stodola
A: 

Try the following:

#sitewrap {
   position:absolute;
   top:0px;
   left:50%;
   width:1426px;
   margin-left:-713px;
   background: url(../images/bg.jpg) no-repeat ;
}

This will be centered but will overflow the browser window.

Travis