http://www.webmasterworld.com Welcome to WebmasterWorld Guest from 38.103.63.17
register, login, search, glossary, subscribe, help, library, PubCon, announcements , recent posts, unanswered posts
Subscribe and Support WebmasterWorld
Home / Forums Index / Browser Side World / CSS
Forum Library : Charter : Moderators: DrDoc & Robin reala & SuzyUK

CSS

  
gap between div in Internet Explorer
Zuna


#:3607397
 4:31 pm on Mar. 21, 2008 (utc 0)

Hello all.

I am totally new to CSS layout but I have spent the last 4 days reading books and articles online, so I feel comfortable with the syntax and the "theory" behind CSS and CSS positioning.

I am attempting to put together a 2 column layout with a header and a footer. The layout works properly in Firefox, but it does not work properly in Internet Explorer 7. The trouble I am having is there is a gap between the header div, and the columnLeft and columnRight divs.

This gap does not appear in Firefox or Safari.

I have read many articles concerning this type of bug and they all point to the "collapsing margins" issue, which I somewhat understand but the workaround of removing the margins from the first tag that appears in the div does not appear to be working.

Note also that the "bug" only appears when I use an image in the header div. If I replace the image with <h1>header test</h1> then all the divs line up against each other (which is exactly what I want).

I have spent a lot of time trying to troubleshoot this and I'm just too new to CSS layout to understand why the gap is appearing. I really appreciate any assistance you can offer.

As an aside, I have validated both the HTML and the CSS using the validator tools at validator.w3.org.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="/css/test.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="container">

<div id="header">
<img src="/images/header/top_cap.gif" alt="top cap" width="720" height="30" />
</div>

<div id="columnRight">
<h1>columnRight</h1>
</div>

<div id="columnLeft">
<h1>columnLeft</h1>
</div>

<div id="footer">
<h1>footer</h1>
</div>

</div>
</body>
</html>

And here is the very simple stylesheet:

@charset "UTF-8";
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}

#container {
width: 720px;
margin: 0 auto;
border: 1px solid #000000;
text-align: left;

background: red;
}

#header {
width: 100%;

background: orange;
}

#columnRight {
float: right;
width: 50%;

background: blue;
}

#columnLeft {
float: left;
width: 50%;

background: green;
}

#footer {
clear: both;
width: 100%;

background: yellow;
}

h1 {
margin: 0;
}


Zuna


#:3607407
 4:51 pm on Mar. 21, 2008 (utc 0)

<sigh>

It never fails that when I finally get the courage to post a question on a forum, I manage to stumble upon the answer:
<snip>

adding the following style to the image tag:

img {
vertical-align:bottom;
}

solves the problem.

Now I just need to spend some time and figure out WHY it behaves that way so I understand what the fix actually does.

The post above also suggested two sites:

http://developer.mozilla.org/en/docs/Images,_Tables,_and_Mysterious_Gaps

Which I plan to review.

[edited by: SuzyUK at 6:17 pm (utc) on Mar. 21, 2008]
[edit reason] no non-authority links thanks, see TOS/Charter [/edit]

SuzyUK


#:3607468
 6:22 pm on Mar. 21, 2008 (utc 0)

Hi Zuna and Welcome to WebmasterWorld!

Glad you found your answer, sorry some links had to go (have a read of the posts pinned to the top of the forum when you get some time), but the mozilla link I've left in is considered the authority (was formerly hosted on Netscape!) on the subject and will give you the best answer in diagrams to help understand the whys and wherefores

any questions though feel free to ask, and again Welcome!

[edited by: SuzyUK at 6:25 pm (utc) on Mar. 21, 2008]

 

Home / Forums Index / Browser Side World / CSS
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of WebmasterWorld Inc.
© WebmasterWorld Inc. / SearchEngineWorld 1996-2008 all rights reserved