Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

whats the change of 2em area - " margin: 0 auto 2em; "

Hello,

whats the change of 2em area - " margin: 0 auto 2em; ?

When it comes to 1px, 2px, 3px, 4px = top, right, bottom, left and also 1px 2px only = each 2 side.

But what does this mean when auto goes 1st and then 2em after? Whats the position change of this?

1 Answer

Steven Parker
Steven Parker
229,644 Points

When 3 values are given, the 4th is implicitly set the same as the 2nd. So margin: 0 auto 2em; is the same as margin: 0 auto 2em auto;.

And when horizontal margins are set to "auto", then the item is centered in the available space.

So the total setting is no top margin, item centered left and right, and a 2em bottom margin.