The power of margin: auto;

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

I know this is a really really noobish thing, but I couldn’t, for the life of me, figure out how to get a couple of things centered on a website I was working on.  I looked all through my copy of CSS: The Missing Manual, but it didn’t describe it anywhere.  So I did some searching online and found an about.com page that said the easiest way to center something is to use margin: auto;  This works great for all browsers except IE6 and below.  For that I just gave the same div text-align: center; and everything was great.  I don’t know why I didn’t figure it out before, but it really makes sense now.  It is putting the same amount of margin on either side of it.

blog comments powered by Disqus



Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States