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

Jack Fitzgibbon
Jack Fitzgibbon
7,607 Points

Margins

I do not understand what the margin property does, and how it affects a webpage, and how the auto value for the margin property works.

#wrapper {
     margin: 0 auto;
}

I do not understand the above rule.

2 Answers

Ruben Leija
Ruben Leija
4,051 Points

The margin clears an area around an element (outside the border). The margin does not have a background color, and is completely transparent.

wrapper {

 margin: 0 auto;

}

The first argument represents top and bottom margin the second argument represents the left and right side. The 0 says no margin at the top and bottom and auto means equal on both sides.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

margin: 0 auto; automatically calculates where to display the wrapper in the browser. If for example you had a wrapper with a width of 70%, the margin displays it at 0 from the top and an auto left and right, so it fills up the remaining space on the left and right, giving the effect of centering the element on the screen. :)