SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple CSS Margin Question

    Why is the margin for the 'paragraph' element bursting out of the main container and creating a margin between the Top of the '#main' container and the top of the window?

    If I set margin to 0 on the 'p' element, the space between the outer container of the 'p' and the top of the window disappears. Why is this? shouldn't the space for the margin of the 'p' element be shown inside of the containing element?

    Thanks,
    Curtis

  2. #2
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, found an answer after tweaking search terms.

    Any additional info is welcome

    http://stackoverflow.com/questions/1...parent-element

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is that not a glitch? Is it because it was implemented as a mistake and now it would break to many sites to change it??

    Setting overflow to hidden or auto will make the margin work 'properly (imo)' but having overflow set to visible and all of a sudden the margin breaks out of the containing box and acts as if it's a margin on the containing box...

    Is there something useful about the default behavior that I am missing or is it a legitimate quirk that just has to be worked around most of the time?

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    It's an aspect of "collapsing margins" ... definitely not a bug. As long as you are aware of it, it's not a problem to work with.

    If it's a problem, you can easily do something like

    Code:
    p:first-child {margin-top: 0;}

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    good stuff here

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by cavcurt View Post
    good stuff here
    Yes, there are some great people around here, including Paul O'Brien, the author of that Reference I linked to.

    Hope we see you again soon.

  7. #7
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Yes, there are some great people around here, including Paul O'Brien, the author of that Reference I linked to.
    Co-author. Don't forget the Mad Swede.


Bookmarks

Posting Permissions

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