Understanding margin 0 auto
What exactly is happening when you type margin 0 auto
The most common way to center elements in CSS, is to write margin:0 auto;, or to use the margin-left:auto; margin-right:auto; which is almost the equivalent of the first deceleration.
The Margin shorthand property sets all four values in one deceleration.
margin:0 auto;
The above declaration sets the top margin to 0, and the left and right margins to auto. This is because the first value is copied for the opposite value. This means that a declaration like the below is just a waste of bandwidth.
margin:0 auto 0 auto;
When you Remember that the order of the declaration is: top, right, bottom, left, and that the first value just gets copied, it will be a lot easier to save yourselves from unnecessary CSS codes.