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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    120
    Thanks
    13
    Thanked 3 Times in 3 Posts

    div height issue

    i have a background image that has 2px of height, and I need it to be put in div.
    So, i simply code:

    Code:
    <div style="background-color:black;width:100%;height:2px"></div>
    (as you can see, i removed the 'background-image' from the code, cos thats not really the issue)

    Just why the heck wont the damn div have 2px of height in Internet Explorer? If you open it on Mozilla Firefox it will work fine, but on IE, the div will be about 10px of height! WHYY?

  • #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
    Quote Originally Posted by Dhuan View Post
    i have a background image that has 2px of height, and I need it to be put in div.
    So, i simply code:

    Code:
    <div style="background-color:black;width:100%;height:2px"></div>
    (as you can see, i removed the 'background-image' from the code, cos thats not really the issue)

    Just why the heck wont the damn div have 2px of height in Internet Explorer? If you open it on Mozilla Firefox it will work fine, but on IE, the div will be about 10px of height! WHYY?
    Did you put this in the top of your CSS?
    * {margin:0;padding:0;border:0;}

    If not, try it and see if it helps. Make sure you have a good doctype declaration too.

    Also, a link to a live test page is the best way to get help. Second to that is posting your full code so that we can see if you have accidentally added margins, padding, or anything else to the trouble div.
    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
    Regular Coder
    Join Date
    Mar 2009
    Posts
    120
    Thanks
    13
    Thanked 3 Times in 3 Posts
    Did you put this in the top of your CSS?
    * {margin:0;padding:0;border:0;}

    If not, try it and see if it helps. Make sure you have a good doctype declaration too.

    Also, a link to a live test page is the best way to get help. Second to that is posting your full code so that we can see if you have accidentally added margins, padding, or anything else to the trouble div.
    thanks for trying, but it didnt help...
    i set all those (margin,padding,border) to 0 and it didnt work...

    as for the full code, thats the full code.... i simply want to make a thin (2px) div, and if i use the mentioned code it works fine on Firefox, but it looks like Internet explorer has a minimum height of 10px for divs...

    make a file (test.html) the write this code on it (you can even try to set the borders to 0, it'll make no difference on IE):
    Code:
    <div style="background-color:black;width:100%;height:2px"></div>
    and then you'll see what i'm talkin about.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Add font-size:0; to your div's style
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Dhuan (05-13-2009)

  • #5
    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
    Quote Originally Posted by Dhuan View Post
    thanks for trying, but it didnt help...
    i set all those (margin,padding,border) to 0 and it didnt work...

    as for the full code, thats the full code.... i simply want to make a thin (2px) div, and if i use the mentioned code it works fine on Firefox, but it looks like Internet explorer has a minimum height of 10px for divs...

    make a file (test.html) the write this code on it (you can even try to set the borders to 0, it'll make no difference on IE):
    Code:
    <div style="background-color:black;width:100%;height:2px"></div>
    and then you'll see what i'm talkin about.
    OK, well did you add the doctype as suggested? For example, this works perfectly in IE7 until the doctype is removed:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>DIV</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    <body>
    <div style="background-color:black;width:100%;height:2px"></div>
    </body>
    </html>
    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

  • Users who have thanked Rowsdower! for this post:

    Dhuan (05-13-2009)

  • #6
    Regular Coder
    Join Date
    Mar 2009
    Posts
    120
    Thanks
    13
    Thanked 3 Times in 3 Posts
    Add font-size:0; to your div's style
    That's it!! Well done! Now the div box is with the height of 2px! Thanks, abduraooft!

    OK, well did you add the doctype as suggested? For example, this works perfectly in IE7 until the doctype is removed:
    Hey, that worked too, with that, i didnt even need to set the font size to 0. Thanks again, Rowsdower!

  • #7
    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
    Sure thing, good luck with the rest of the site!
    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

  • #8
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sometimes line-height:0 helps too. Good luck!


  •  

    Posting Permissions

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