troubleshooting Question

Vertical gap between two floated elements

Avatar of tolvor
tolvor asked on
CSSHTML
1 Comment1 Solution781 ViewsLast Modified:
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>
headerpic.jpg
ASKER CERTIFIED SOLUTION
Jeffrey Dake
Senior Director of Technology

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros