thundercade64 Posted March 14, 2006 Share Posted March 14, 2006 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 More sharing options...
vchris Posted March 14, 2006 Share Posted March 14, 2006 body { text-align: center; } /* centers in IE */#container { margin: 0 auto; } /* centers in everything else */ Link to comment Share on other sites More sharing options...
aspnetguy Posted March 14, 2006 Share Posted March 14, 2006 body { text-align: center; } /* centers in IE */#container { margin: 0 auto; } /* centers in everything else */<{POST_SNAPBACK}> #container{width:###px;margin:0 auto} Works in IE too, just have to set a fixed width. Link to comment Share on other sites More sharing options...
vchris Posted March 14, 2006 Share Posted March 14, 2006 #container{width:###px;margin:0 auto} Works in IE too, just have to set a fixed width. <{POST_SNAPBACK}> hmmm... no it doesn't. I copied your code and added a width of 750px and it's not centered. Link to comment Share on other sites More sharing options...
thundercade64 Posted March 14, 2006 Author Share Posted March 14, 2006 hmmm....I've tried {margin: 0 auto;} but it doesn't seem to do anything to center in FireFox.What could I be doing wrong? Does anyone have some simple code that they have tested in FF they could copy here? This is just driving me nuts. Link to comment Share on other sites More sharing options...
aspnetguy Posted March 14, 2006 Share Posted March 14, 2006 hmmm... no it doesn't. I copied your code and added a width of 750px and it's not centered.<{POST_SNAPBACK}> <!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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now