Avatar of tolvor
tolvor
 asked on

Vertical gap between two floated elements

I have two elements, one a title bar, and one a graphic.  The title bar contains a floated element (h1), and the graphic itself is floated left.  However between the two is a mystery gap. The gap has something to do with the floats because if they are removed, the gap disappears, however I do need the floats.  I've tried various clearing methods after the titlebar div, and setting the font to 0, and the various margins to 0, but the gap remains.

The code passes w3c html and css validation checks.  It displays *correctly* in IE6, but *not* in FF3.0.

I'd appreciate if you could show how to get the two elements to be adjacent and without the gap.

This has been stumping me and have researched this and still can't find what's happening.
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>SiteTitle</title>
<style type="text/css">
 
p, h1, h2 {margin-top: 0; padding: 0;}
 
html, body {margin:0; padding:0; left:0; margin-top:0;padding-top:0; font-size: 0;}
 
body {
  font: 100% Arial, Helvetica, sans-serif;
  font-size: small;
  margin: 0; 
  padding: 0;
  text-align: center; 
}
 
/* ===================Right Header Container=========================  */
 
 
#header_righttopbar {
  background-color: #000;
  height: 30px;
}
 
.header_title {
  float: left;   /* this must be floated */
  margin-top: 0px;
  padding-top: 0px;
  width: 55%;
}
 
#header_righttopbar h1 {
  text-align: left;
  color: #0f0;
}
 
#contentcolumn{   
  float: left;      
  color: #000;
  border-top: 0px;
  font-size: small;
}
 
#rightcolumn{         
  font-size: 0px;
  border-top: 0px;
  padding-top: 0px;
  margin-top: 0px;
  float: left;         /* if this is removed, gap will disappear - this must be 
 
floated  */ 
  width: 510px; 
  height: 339px;
  background-image: url("headerpic.jpg");
  background-repeat: no-repeat;
}
 
/* I've tried scattering this around, doesn't help */
.clearfloat { /* this class should be placed on a div or break element and should 
 
be the final element before the close of a container that should fully contain a 
 
float */
  clear:both;
  height:0;
  font-size: 1px;
  line-height: 0px;
}
 
</style>
 
</head>
 
<body>
  <div id="header_righttopbar">
    <h1 class="header_title">Title</h1>
  </div>
 
  <div id="rightcolumn">
    <p>testing 1 2 3</p>
  </div>
 
</body>
</html>

Open in new window

headerpic.jpg
CSSHTML

Avatar of undefined
Last Comment
Jeffrey Dake

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jeffrey Dake

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23