Grow your CSS skills. Land your dream job.

how to control the margins

  • # June 17, 2013 at 3:21 am

    hi

    this is zeeshan. how can i take the margin of the div from top. when the div having the css margin:0 auto;
    div{
    width:500px;
    height:540px;
    text-align:center;
    display:block;
    border:3px solid #d4d4d4;
    margin:0 auto;
    }

    # June 17, 2013 at 3:31 am

    div{
    margin: 50px auto 0 auto;
    }

    Margin goes clock-wise. The first value is for top, the second value is for right, the third value is for bottom and the fourth value is for left. So if you add the code above, then you are telling the div to shift down by 50px from top.

    # June 17, 2013 at 3:35 am

    Im not sure if this is what you are asking

    In margin: 0 auto

    0 – represents top and bottom
    auto – means center it horizontally

    If you want to add more top margin make it a full declaration margin: top right bottom left.

    If you are having extra margin and dont know where its coming from you should post a link to your site

    # June 17, 2013 at 3:36 am

    add one more div and you can control the margin. See the[ codepen](http://codepen.io/anon/pen/pDBrF “”)

    Or you can just set as
    margin: 20px auto 0

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".