treehouse : what would you like to learn today?
Web Design Web Development iOS Development

CSS formatting preference

  • Just curious to see which of these is preferred and why.

    margin: 0 0 20px 0;
    

    or

    margin-bottom: 20px;
    

    I tend to use the upper method in case I ever want to quickly make changes.

  • If I just want bottom margin, I'll use the second option.

    I don't see any need to tell the browser NOT to do something it wasn't going to do anyway...but I'm not going to be a css-nazi about it.

  • I generally use the longhand property. Shorthand can unknowingly override other styles.

  • i use the first format, be specific as i can .

  • Yeah, I like the idea of not telling the browser what not to do also, but sometimes the browser defaults screw with things, so adding the zero margins make it specific. I guess then, if you use normalize or a reset, you're telling the browser a whole lot of what not to do!

    Thanks for the feedback as usual.

  • Depends so much on the issue. Normally, use the longer version. However, when overriding another (general) style, the short version is preferred.

  • When there is only one direction out of 4 concerned, I use the long hand version. But for maintainability, the short hand may be easier.

  • If I'm creating a grid I only do long hand as I figure any other classes I add to the div may need their own margins etc.

    However, if it's a lonesome individual element then yes I would probably shorthand it.

  • The top one if I'm specifying more than one margin, otherwise the bottom one.