There are many ways to center HTML content horizontally on the page. Traditionally, many webmasters use tables for layouts, and often solely to center content horizontally; some use floating divs; some even revert to absolute positioning and usage of JavaScript.
Today I’m glad to tell you about a very easy, very fast, and very predictable way of centering your content horizontally. Meet the display: inline-block CSS rule!
As soon as you apply it to the divs you need to center, just add the text-align: center rule to their container, and you’re done! Your divs will maintain their alignment at all times, from very small to very large window widths. You can see a demonstration here; remember to check out the source code to see how cleanly it looks.
Update
Apparently Internet Explorer can only assign inline-block display type to elements that are natively inline (such as spans). So we just replace divs with spans, and voila! Everything works now in IE, too, while nothing changes in other browsers.
Update 2
Pay attention to the “vertical-align: top” CSS rule. Without it, IE would align the tallest span in the row by the bottom of the row, while Firefox and Webkit-based browsers align such spans by the top of the row by default. Adding this rule allows our markup to look completely uniform in all major browsers.
Update 3
It is also possible to achieve the desired effect without reverting to spans: use IE conditional comments to tell it that divs are inline, while all other browsers get the inline-block rule. This will allow your markup to remain valid from W3 specs point of view even when you need to inject block elements into your centered elements (doing so with spans will violate the specs). I will update my example accordingly.
There are only two minor caveats to keep in mind (both of them are illustrated in the supplied example page):
1) In the end of the horizontal block you want to center, put a
element.
2) Comment out newlines between elements in a horizontal block, otherwise in some browsers you will see white spaces between them.
Please report if you find a case where this method fails to deliver.
Posted by rumith
Posted by rumith 
Posted by rumith