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 trialSinar Brenes Jr
364 PointsDifferent Values for the Margin Declaration
Why is there sometimes two values given for this declaration instead of one? That is to say, for example, why is it sometimes okay to just put down something like "margin: 0;" instead of having to put down something like "margin: 0 auto;"? Won't both of these values do the same thing or will each do something different?
1 Answer
bleedcmyk
5,945 PointsWith margin tags, it works like this;
Margin: (Top) (Right) (Bottom) (Left); Example;
Margin: 50px 25px 25px 50px;
Margin: (Top) (Right & Left) (Bottom);
Margin: 50px 25px 50px;
Margin: (Top & Bottom) (Right & Left);
Margin: 50px 25px;
Margin: (All margins);
Margin: 50px;
So when you set Margin: 0 auto;
Its actually setting your top and bottom margins to 0 and your left and right margins to "auto" which center positions your div horizontally.
Also Auto doesnt = 0. Auto means your browser is auto calculating your margin.