Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

CSS "top" and "margin-top"

  • 17-01-2010 09:42AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 490 ✭✭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,698 ✭✭✭tricky D


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


Advertisement