2 replies [Last post]
etrilliat
Offline
newbie
Yorkshire,UK
Last seen: 14 years 24 weeks ago
Yorkshire,UK
Joined: 2004-06-09
Posts: 10
Points: 0

i am having trouble centering a web site. i am building a site 750 wide for 800x600 but want it centered on 1024+. as i understand css best practise, you should center a 750 wide div with left and right margins set to auto. i have done this and while it looks centered it is actually slightly off center. it is not that noticable on 1024+ but on my test machine 800x600 it is noticably off center due to little spare margin. any help and advise appreciated. i am probably missing something really basic Sad
btw, i have set the body to 0 left margin and using IE6.

homchz
Offline
Enthusiast
Last seen: 15 years 48 weeks ago
Joined: 2004-07-23
Posts: 77
Points: 0

centering a web page

Here is my CSS

body{
	background-color:#FFFFFF;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px;
	text-align:center;
}

div{
    text-align:left;
}

#centered{
	background-color:#E6E6E6;
    width:755px;
    margin-left:auto;
    margin-right:auto;
}

I use

<div id="centered">
Rest of the web page HTML
</div>

You can change the width and color to whatever you want.

Hope this helps

Josh
[/code]

etrilliat
Offline
newbie
Yorkshire,UK
Last seen: 14 years 24 weeks ago
Yorkshire,UK
Joined: 2004-06-09
Posts: 10
Points: 0

centering a web page

thanks for your help homchz. however i have found the solution, and i was right, missed the basics. i forgot to set the right margin in the body to 0px. :oops: