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 trialPatrick Sakai
Courses Plus Student 527 PointsSo what causes the wrapper to center?
I got it to center, but I still want to understand more the intuition of why the wrapper centers. Because we didn't type in "center" in the code.
2 Answers
Ryan Field
Courses Plus Student 21,242 PointsWhen you set margin: 0 auto
, you are telling the page to set the element to have a 0px margin top and bottom, and auto on left and right, which sets them to be the same, effectively centring the div.
Alexander Mooney
7,321 PointsTo add on to Ryan's answer, the auto is also the reason the margins grow or shrink on the left and right sides of the page as you resize the window.