Treehouse: Grow your CSS skills. Land your dream job.

CSS formatting preference

  • # October 14, 2012 at 6:11 am

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

    margin: 0 0 20px 0;


    margin-bottom: 20px;

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

    # October 14, 2012 at 7:19 am

    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.

    # October 14, 2012 at 7:37 am

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

    # October 14, 2012 at 8:19 am

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

    # October 14, 2012 at 9:14 am

    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.

    # October 14, 2012 at 10:39 am

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

    # October 14, 2012 at 10:54 am

    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.

    # October 14, 2012 at 12:22 pm

    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.

    # October 14, 2012 at 1:10 pm

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

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.