Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

CSS "top" and "margin-top"

Options
  • 17-01-2010 10:42am
    #1
    Registered Users Posts: 1,086 ✭✭✭


    In CSS are these the same?
    p
    {
    margin-top:2cm;
    }
    
    p
    {
    top:2cm;
    }
    

    Or does "top" mean not mean margin?


Comments

  • Registered Users Posts: 489 ✭✭Pablod


    p
    {
    margin-top:2cm;
    }
    
    This is the correct one to use,
    The second piece of css does not apply any margin,

    Also if you are applying, all margins to top,right,bottom,left
    it would be
    p
    {
    margin: 2cm 0cm 0cm 2cm;
    }
    

    margin: 2cm 0cm 0cm 2cm; = margin: top(2cm) right(0cm) bottom(0cm) left(2cm)

    Hope this helps


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Peter B wrote: »
    In CSS are these the same?
    p
    {
    margin-top:2cm;
    }
    
    p
    {
    top:2cm;
    }
    

    Or does "top" mean not mean margin?

    "top" is only relevant if the CSS target object also has "position:absolute" or "position:relative"

    If it's position:absolute then all of the "<p>"s would be overlapping - they'd all have the same "top" co-ordinates.

    If it's position:relative then the effect on the target object is roughly the same as margin (although other items on the page are affected since the object is no longer "inline").


  • Closed Accounts Posts: 9,700 ✭✭✭tricky D


    Info on top and other positioning properties:
    http://www.w3schools.com/css/css_positioning.asp


Advertisement