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 Center the Wrapper

Patrick Sakai
PLUS
Patrick Sakai
Courses Plus Student 527 Points

So 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
PLUS
Ryan Field
Courses Plus Student 21,242 Points

When 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.

To 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.