July 23, 200917 yr Hi folks. I've came across a little problem on with a site i've been working on, infact, the same problem on a couple of sites and i'm just wondering if there is a way around it. I've used the, pretty common method of centering my site by using position:absolute; left:50%; margin-left:'minus half the width of the div' The problem is...if the windows width is reduced to anything below 'width of the div' the left hand side of the page begins to cut off, and because you can only scroll right, the content is essentially useless. Is there a way i can fix this. Maybe using javascript or something (my knowledge of javascript is limited, but i thought something like this might be along the lines of what i need? lets say the width of the div needing centered is 1000px <script> function setMargin() var width =document.documentElement.clientHeight/Width; var difference = 1000 - document.documentElement.clientHeight/Width; if (width < 1000) { document.getElementById('the_div').object.style.marginLeft = difference;} else {document.getElementById('the_div').object.style.marginLeft="-500";} </script> The site i'm working on just now can be viewed At this location Reduce the window size and you will see my problem. Maybe javascript isnt the way to fix it, so any suggestions would be much appreciated. Thanks.
July 23, 200917 yr Yes to centre a site use: #wrapper { width: what ever height in px/ %; margin-left: auto; margin-right: auto; } This will centre your website. - You will need to use text-align: center for ie6 and older but just redeifne left on the wrapper container!
July 23, 200917 yr Author AAaach, thanks adam. I did try that earlier, but never took out the position:absolute 's so it stayed the same. [slaps head] Thanks.
Create an account or sign in to comment