views:

36

answers:

4

I am a little bit confused. Here is a small web page. There are two main div-s: top and mainBlock.
First contains an image. The problem is that firebug shows that div#top's height is equal to 0 and because of that the next div mainBlock moves up. If I would delete this piece of code:

div#logo{
    float: left;
} 

everything will start working fine and div#mainBlock will be below the div#top. Could you, please, explain me how it works and how to avoid this in proper way?

Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Paralab - Website &amp; interface design, web apps development, usability</title>
<style text="text/css">
html, body{
}
div#logo{
    float: left;
}
#top{
  width: 100%;
}
#mainBlock{
  width:100%;
}
</style>
</head>
<body>
    <div id="top">
        <div id="logo">
            <img alt="logo"  src="img/logo.png" />
        </div>
    </div>
    <div id="mainBlock">
        Contact Us
    </div>
</body>
</html>
+1  A: 

because it's floating - add clear:left; to your mainBlock class.

http://jsfiddle.net/XEaBT/

Dan Heberden
Thank you! It works!
andrii
+1  A: 

You need to clear your float. There are a few ways to do this, I'd check out this article on QuirksMode about clearing floats for more info.

Jimmy
Thank you, especially for the article. Now I caught the point!
andrii
A: 

Floated images leave the flow of the document. Set #top{overflow:hidden;}

edl
A: 

I would highly recommend that you use a strict doctype instead of transitional. You will get more consistent behavior across browsers.

Chris Lively