space between divs

Discussion in 'HTML & Website Design' started by snowLee, May 13, 2008.

  1. #1
    I have something like this:

    
    <div id="container">
    
    <div id="one">Some text
    </div>
    
    <div id="two">Another text
    </div>
    </div>
    
    HTML:

    and in the IE browser I have a small space on the output between "one" and "two", that isn't on Firefox.
    I put all of these zero: margin, padding, border, but the space is still there, and only in IE.
    What's the problem?

    Thank you.
     
    snowLee, May 13, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    try
    <div id="container">
    	<div id="one">Some text</div><div id="two">Another text</div>
    </div>
    Code (markup):
    just like that

    IE looks at a physical line break and ads a space thinking its doing the right thing :p so you must keep them on the same physical line.
     
    crath, May 13, 2008 IP
  3. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    I tried, but the space it's still there
     
    snowLee, May 13, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    is the page online?
     
    crath, May 13, 2008 IP
  5. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    yes
    uppervalley.ods.org/smaranda/acasa.html

    without www
     
    snowLee, May 13, 2008 IP
  6. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    If you look to the source code I put a comment where I have that space in the output.
     
    snowLee, May 14, 2008 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Every browser has its own defaults for things like margin and padding. Since changing code to make one browser look right often screws up another, we set everyone to 0 so that we're starting from the same point for everyone.

    This might screw with other parts of your page if you were relying on default margins and padding on other elements, but you can add this:

    
    * {
      margin: 0;
      padding: 0;
    }
    body {
    margin-bottom: 10px; <-- I'd make this padding-bottom instead, but that's me
    background-color: #eee;
    }
    
    Code (markup):
    The * means "everything" so then you don't need to say margin: 0 padding: 0 on everything (biggest problem between browsers is lists, so I really love this for lists).
     
    Stomme poes, May 14, 2008 IP
  8. web-master

    web-master Peon

    Messages:
    838
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Just had a play with your page. I moved the </div> for the "top_picture" onto the same line as the <div> for that section and the space disappeared.

    It now looks like below and works well
    Hope this helps
    Web-Master
     
    web-master, May 14, 2008 IP
  9. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    Brother you have right.
    I thought that doesn't matter how I have the code arranged, but I saw that I was wrong.

    Thank you
     
    snowLee, May 14, 2008 IP
  10. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #10
    And yet I don't have a single extra space in any page I've coded, and almost all of my divs are not written inline but as so:
    <div>
    stuff
    more stuff
    etc
    </div>

    It does not normally matter, because the browser is supposed to ignore whitespace in code. So I'm still assuming it's some default margin or padding in IE.
     
    Stomme poes, May 14, 2008 IP
  11. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #11
    Brother believe me that I tried almost everything, even with *, like you said, but web-master gave me an idea and worked.
    I think like you, because it's the first time when I have this problem, and always I don't care too much how I put the code.
     
    snowLee, May 14, 2008 IP
  12. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hey if it works, use it! But it would bother me if it happened to me because I'd want to know what's causing it... since it's an image it occurred to me that it might be that bit of space at the bottom of all inlines (making room for hanging letters like g and p) where either display: block or vertical-align: bottom also removes the space, and tends to show up in IE rather than other browsers.
     
    Stomme poes, May 14, 2008 IP
  13. web-master

    web-master Peon

    Messages:
    838
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Glad to be of assistance for once!

    Web-Master
     
    web-master, May 14, 2008 IP