473,466 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Div height issue in IE 6

2 New Member
Hi,

I'm pretty new to web development and I just spent the better part of the morning trying to figure out this IE bug. I came up with a hack that makes no sense to me. I would appreciate if someone could explain why this situation occurs, and if there is a better solution!

I am trying to stack 2 divs on top of each other. The divs should be 5 pixels tall and touching each other. (In my website, these are actually containers for top and bottom rounded-corners images, so they must be no taller than the background-image I'm putting inside each of them). It works in Firefox, but in IE, the divs become much larger.

The hack that I came up with is to set font-size: 4px in the body style, as shown below. This forces the divs to the correct height even though the divs contain no text, and even though I explicitly set the div's height to 5px (which seems to have no effect in IE).

Here is some very simplified code that exhibits the problem. It does validate.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html>
  5. <head>
  6. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
  7. <link href="styles.css" rel="stylesheet" type="text/css" />
  8. <title>Test</title>
  9. </head>
  10.  
  11.  
  12. <body>
  13.  
  14. <div id="myDiv1"></div>
  15. <div id="myDiv2"></div>
  16.  
  17. </body>
  18.  
  19. </html> 
  20.  
  21.  
And the CSS:

Expand|Select|Wrap|Line Numbers
  1. body, p, ul, a, img {
  2.     padding: 0;
  3.     margin: 0;
  4.     text-decoration: none;
  5.     border: none;
  6.         font-size: 4px; //This is the hack that fixes the spacing in IE
  7. }
  8.  
  9. #myDiv1 { 
  10.     background-color: #ff0000;
  11.     height: 5px;
  12. }
  13.  
  14. #myDiv2 {
  15.     background-color: #000000;
  16.     height: 5px; 
  17. }    
  18.  
Can anyone reveal the nature of this mystery so that I can deal with it properly in the future? Thanks! =)
Jun 26 '07 #1
1 2077
jsavagedesign
17 New Member
I've seen this happen as-well. Acually, thanks for the tip.
I bet it has something to do with how IE handles empty tags , kinda like when you make a table and you have an empty cell.

recommend this
<tr>
<td>&nbsp;</td>
</tr>

instead of
<tr>
<td></td>
</tr>
Jun 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5">...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
18
by: Francois du Toit | last post by:
Can someone confirm this: http://www.purpleray.za.net/opera_bug.html
3
by: TheXenocide | last post by:
Hello, First and foremost I'll describe a bit about my problem: I'm trying to make a site layout using ASP.NET 2.0 in Visual Studio .NET 2005 Beta 2. The site is a table based layout that is...
13
by: Haines Brown | last post by:
I have a style for a list: dl { line-height: 1; margin-bottom: 1em; } But the W3C CSS validator says: Line: 124 Context : dl Invalid number : line-height Parse Error -
6
by: R144N | last post by:
Hi Everyone, I have finally taken the step to bring a site to the 21st century with HTML 4.01 with the height tag having been deprecated. I have read numerous articles claiming that the CSS...
2
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I have a gridview and I need it to display correctly in Opera. I need to set the row height, so that even on the last page of data all the rows are the same height as on the other pages. ...
6
by: doug | last post by:
I am loading some HTML into a lightbox div via AJAX. What I would like to do is load the HTML into the lightbox div (a scrollable one), then get the height of the content of the div (not the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.