amakeler Posted February 20, 2007 Share Posted February 20, 2007 Hi all, Subject: newbie q: How do you horizontally center (align) a div ?I have looked thru all the CSS commands, but for some reason I could not seem to find a command to horizontally center (align) a <div>. I have taken somebody's good advice to put all my content in some sort of #content div, but now I have decided to make the content a certain width, say 900px, I can't find a way to center the #content div in the center of the browser window.So surely there must such a command? Thinking...or maybe not, coz every time somebody widens the browser the whole content will have to jump.Anyway...need help.avraham Link to comment Share on other sites More sharing options...
real_illusions Posted February 20, 2007 Share Posted February 20, 2007 its pretty simplein your css you need#content{margin: 0px auto;width:900px;}the #content been the id of the div that is the main one encasing all your content. Link to comment Share on other sites More sharing options...
S@m Posted February 20, 2007 Share Posted February 20, 2007 Great example how to center your layout. Super easy.http://www.simplebits.com/notebook/2004/09/08/centering.html Link to comment Share on other sites More sharing options...
real_illusions Posted February 20, 2007 Share Posted February 20, 2007 you shouldn't need the text align attribute for the body.As saying text-sling:left; in every other element means extra bytes to d/l from the css, a bit useless in my opinion, And it says on that site that its for ie5 for windows. Who the heck uses ie5 nowadays? Link to comment Share on other sites More sharing options...
croatiankid Posted February 20, 2007 Share Posted February 20, 2007 you shouldn't need the text align attribute for the body.As saying text-sling:left; in every other element means extra bytes to d/l from the css, a bit useless in my opinion, And it says on that site that its for ie5 for windows. Who the heck uses ie5 nowadays? Yeah since IE7 came out I've completely disregarded support for ie5.By the way, if you're being so nitpicky about extra bytes....#content#id{margin: 0px auto;width:900px;} can be #id{margin: 0 auto;width:900px;} Link to comment Share on other sites More sharing options...
jesh Posted February 20, 2007 Share Posted February 20, 2007 By the way, if you're being so nitpicky about extra bytes....can be #id{margin: 0 auto;width:900px;} Why not:#id{margin:0 auto;width:900px;} then? Link to comment Share on other sites More sharing options...
BiteMe Posted February 21, 2007 Share Posted February 21, 2007 one other thing. Dont call yourself newbie.Y would you do that? No one calls themself newbie.....newbie Link to comment Share on other sites More sharing options...
otenjoxi Posted February 21, 2007 Share Posted February 21, 2007 If you're having any issues in IE 6 or below, try this:body{ text-align: center; /* ie fix */}div#wrapper{ text-align: left; /* fixes the ie fix */ margin: 0 auto; width: 750px; /* must have a width or it defeats the purpose */} Link to comment Share on other sites More sharing options...
otenjoxi Posted February 21, 2007 Share Posted February 21, 2007 An example situation would be if you wanted to center a wrapper div that was a direct descendant of the body. 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