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!
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
i 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.
margin: 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 AndersTreehouse Moderator 145,855 Points
Just a whole lot less typing, which makes for less lines of code. Consequently,
is also the same as the two ways you indicated above. Again... just less typing.
Seth Kroger56,412 Points
margin-left, etc. allows you to change one of the values without having to specify (and possibly change due to an error) the others.