...

View Full Version : div height issue



Dhuan
05-12-2009, 11:25 PM
i have a background image that has 2px of height, and I need it to be put in div.
So, i simply 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?

Rowsdower!
05-12-2009, 11:44 PM
i have a background image that has 2px of height, and I need it to be put in div.
So, i simply 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.

Dhuan
05-13-2009, 12:20 AM
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):

<div style="background-color:black;width:100%;height:2px"></div>
and then you'll see what i'm talkin about.

abduraooft
05-13-2009, 10:08 AM
Add font-size:0; to your div's style

Rowsdower!
05-13-2009, 02:12 PM
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):

<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:
<!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>

Dhuan
05-13-2009, 05:19 PM
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!

Rowsdower!
05-13-2009, 05:49 PM
Sure thing, good luck with the rest of the site!

developoor
05-15-2009, 04:15 AM
Sometimes line-height:0 helps too. Good luck!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum