CSS CSS Selectors Selectors - Beyond the Basics DRY CSS

Shahar Golan
Shahar Golan
819 Points

margin: 0 auto 2em;

What the 0 and the "auto means?

1 Answer

Ryan S
Ryan S
27,273 Points

Hi Shahar,

When using the margin shorthand property with 3 values, they represent the following:

margin: top left/right bottom;

Regarding your question, the zero simply means that you are removing the margin from the top of the element.

"Auto", means the browser will automatically calculate the value for the left and right margins. This is particularly useful when you want to center a block level element inside it's container.

Hope this helps.