Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Margin-top to a block affects to the container div.

    Hi,

    I have this page.

    I want to give a margin-top to the logo, but when i do it, the div that contains the logo goes also down, why?

    Regards

    Javi

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    That's because of the "collapsing margins" in the CSS box model:
    http://www.w3.org/TR/CSS2/box.html

    Look at topic 8.3.1 "Collapsing margins"

    Vertical margins may collapse between certain boxes:

    * Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero.
    So, basically, they're sharing.

    You can just use padding-top to get the same effect without the dropdown issue caused by margin collapsing.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    This is because you have used display:block in #logo img {} css, remove display block from your logo image part, then your margin will affect correctly without affecting the overall Div or Container

    Regards
    Ameen


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •