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 CSS Basics (2014) The Box Model The Box Model Review

Adrian Yeow
Adrian Yeow
13,866 Points

Margin: auto

While margin:auto will automatically calculate the margin on each sides of the box, does it also calculate the margin of top and bottom side? From the video, it seems like margin:auto creates space at the left and right hand side of the box.

2 Answers

It gives it a margin-top and margin-bottom of 0. and is centered horizontally.

Tornike Bestavashvili
Tornike Bestavashvili
4,275 Points

You can set the margin property to auto to horizontally center the element within its container.

The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.