Jump to content

Centering the main area on a page - how?


thundercade64

Recommended Posts

I notice that most pages I see the content centered, leaving margins to the side (I'm assuming they do this incase someone is using 800x600 resolution). When I resize (making it narrower) the browser window on these pages, the margins disappear, and the main content stays centered until the margins are gone (e.g. www.gamespot.com, or www.gamefaqs.com).I'm sure this is simple, but i just can't get it. How do I get my main <div> element centered like this? I can get it about centered, but I can't think of a way to code the CSS/HTML to keep it centered and mimic what I described above.Any suggestions?

Link to comment
Share on other sites

hmmm... no it doesn't. I copied your code and added a width of 750px and it's not centered.

<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head></head><body><div style="width:100px;margin:0 auto">hi there</div></body></html>

Try it works!!! You have to use a DOCTYPE or it won't. I just assumed everyone knows you should use a doctype.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...