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 trialEric Trego
15,308 Pointsi was wondering
if margin: 0 0 0 0; is the same as margin-left: 0; margin-right:0; margin-top: 0; margin-bottom: 0; and if they are the same is there a reason to use one form over the other.
3 Answers
Saskia Lund
5,673 Pointsmargin: 0 0 0 0; /* valid but too much code typing */
margin: 0; /* is the same and much shorter */
margin-top: 0; /* these four lines of code equal to margin: 0; */
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
When your goal is to overwrite a margin specifically for the top for example, you'd then use margin-top: somevalue;
Due to the cascading nature of css, this will then overwrite that specific top margin that has already been set to another value earlier in the code by something like margin: 0;
Jason Anders
Treehouse Moderator 145,860 PointsJust a whole lot less typing, which makes for less lines of code. Consequently,
margin: 0;
is also the same as the two ways you indicated above. Again... just less typing.
Seth Kroger
56,413 Pointsmargin-left, etc. allows you to change one of the values without having to specify (and possibly change due to an error) the others.