Geeks With Blogs

Tim Huffam Dotting the I and crossing the T of I.T.

As text-align doesn't work I use a simple work around:

.mydiv{
  width: 100%;
  left: 50%;
}

It's not perfect - but very simple and easy to understand - and you can modify it to suit. 

Seems to work ok in IE 6 & FF 2.0.

Here's another method (http://www.andybudd.com/archives/2004/02/css_crib_sheet_3_centering_a_div/index.php) - but I found it not obvious/simple enough (expecially for others who may have to maintain the css down the track - KISS)

HTH
Tim

Posted on Tuesday, May 15, 2007 5:11 PM ASP.NET , PHP (incl PhpMyAdmin) , Web Development, JavaScript & CSS | Back to top


Comments on this post: Centering div tags using CSS

# re: Centering div tags using CSS
Requesting Gravatar...
#global {
margin-left: auto;
margin-right: auto;
width: ...; /* mandatory to be centered */
}

<div id="global"></div>
Left by Vineet on May 24, 2007 4:42 PM

# re: Centering div tags using CSS
Requesting Gravatar...
For the second time in one week, a Google search for the problem I was having took me to this site, and it solved my problem. Your "how to make a layer clear in GIMP" tutorial saved me some SERIOUS headache as well.

Thanks!
Left by eHarmony Reviews on Feb 02, 2011 6:30 PM

# re: Centering div tags using CSS
Requesting Gravatar...
well, I also frequently focus the cards by making your div. Quite interesting and effective. I think it would be good for many people. Thanks for sharing.
Left by Vietnam Airlines on Apr 09, 2012 10:24 PM

Your comment:
 (will show your gravatar)


Copyright © Tim Huffam | Powered by: GeeksWithBlogs.net