Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout Techniques Float Layout Creating a Horizontal Menu

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.

3 Answers

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 Anders
MOD
Jason Anders
Treehouse Moderator 145,624 Points

Just 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
Seth Kroger
56,403 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.