Div Center Aligned And Margin Auto Problem For IE6 Fixed

If you want to place your div in the center of its container with the help of CSS, you can do so following below process –


Hi

margin 0 sets the margin to 0px and auto sets equal space on either side of the div making it center aligned.
Here both the outer and inner div will be center aligned. The borders are given so that the div blocks can be identified easily.
If we remove margin:0 auto; from the outer class, the outer div will be left aligned with inner div center aligned within it.
For the margin auto to function properly the div must have lesser width than its container.

Problem in IE6

In IE6 sometimes the div gets left aligned even after setting margin auto. This happens if the DTD is not defined properly. If you face this problem in IE6 please provide a valid doctype and the div should be aligned center.

Leave a comment

Your email address will not be published. Required fields are marked *