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 How to Make a Website CSS: Cascading Style Sheets Review: CSS: Cascading Style Sheets

How does margin: 0 auto; center a wrapper element?

I know margin: 0 auto; in a wrapper element will center the wrapper. However, I don't quite understand how the values of "0" and "auto" work there.

1 Answer

robertm
robertm
13,570 Points

"You can set the left and right margins to auto to horizontally center that element within its container. The element will take up the width you specify, then the remaining space will be split evenly between the two margins. " http://learnlayout.com/margin-auto.html

very good explanation there.

The '0' in margin: 0 auto just means that there is no margin for top and bottom.

Hope this helps.

That made a lot of sense! Thanks a lot.