My Layout Breaks When I Add Content. Why?

Discussion in 'HTML & Website Design' started by Masterful, Sep 11, 2009.

  1. #1
    Imagine a simple layout like this:

    <div id="container">
    <div id="header"></div>
    <div id="main"></div>
    <div id="footer"></div>
    </div>
    HTML:
    I have set a background image for my header and footer divs, and a thin background image to repeat vertically down my main div. The images together make a continuous box.

    However, when I add content inside the main div, a gap appears atop and below it. There's no longer a continuous box.

    I fixed the problem by setting the thin background image to repeat vertically down the container div instead of the main div. But does anyone know why it doesn't work when I set it to repeat down the main div?
     
    Masterful, Sep 11, 2009 IP
  2. Sam Designs

    Sam Designs Active Member

    Messages:
    474
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Are you able to give us the link? It'd be easier to work out then.
     
    Sam Designs, Sep 11, 2009 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    kk5st, Sep 11, 2009 IP
  4. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Thanks, Gary.

    That is indeed my problem.

    I tried to give you a rep point but was not allowed. I must have given you rep recently. ;)
     
    Masterful, Sep 11, 2009 IP
  5. squeenix

    squeenix Peon

    Messages:
    57
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah, just use clearfix
     
    squeenix, Sep 12, 2009 IP
  6. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #6
    That makes absolutely no sense.

    gary
     
    kk5st, Sep 12, 2009 IP
  7. stuart.letterman

    stuart.letterman Guest

    Messages:
    143
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Set each DIV with "margin=0" and "padding=0", does this fix things?

    These kind of layouts can be a pain sometimes it's easier using a table to hold all the divs in place.
     
    stuart.letterman, Sep 12, 2009 IP
  8. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #8
    That's the first thing that I tried. It didn't work.

    Tables?

    Come on, dude. :) You should only use tables to present tabular data. For positioning, use CSS.

    Nonetheless, thanks for your attempt. As I explained above, I fixed the problem by setting the main div's background image to vertically repeat down the container div instead. All I wanted was an explanation as to why it wasn't working when I set it to repeat down the main div. This 'margin collapse' phenomenon was the answer.

    I appreciate all the help, guys. :)
     
    Masterful, Sep 12, 2009 IP
  9. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, but if there were no margins to begin with, then there wouldn't be any collapsing. So also setting everyone's margins to 0 should have also removed gaps? (I assume Gary was referring to default margins on your added content like p's, where their margins collapse into the tops of their div parents, your main containers). Child margins basically transferring to their parents is so freaking unintuitive, who thought that was a good idea??? Margin collapse itself is unintuitive. Bleh...

    Though only removing the margins on just the divs wouldn't have worked... the margins would have had to be removed from the content (p?) tags.

    I'm not even sure anymore if divs have default vertical margins in any browser?
     
    Stomme poes, Sep 14, 2009 IP
  10. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yeah the rep system is a joke, there are people who I repped ages ago, and I still cannot give them rep today.
     
    wd_2k6, Sep 14, 2009 IP