hi, I want to create a simple one line height header container with a navigation menu on the left and and a login/logout on the right. I tried to use floating divs in the container, but the result is not what I expected (some kind of wrapping occurs). The html and css are below. Anybody can explain why it does not work? thanks #wrapper{ width: 60em; margin: 1.5em auto; } #header{ background-color: #c1c3bf; } #nav{ float: left; } #login{ float: right; } #content{ width: 40em; float:left; background-color: #e2e5e1; } #sidebar{ width: 20em; float:right; background-color: #a3a5a2; } #footer{ clear:both; background-color: #7a7c79; } Code (markup): <body > <div id="wrapper"> <div id="header"> <div id="nav"> <a href="/">Home</a> <a href="/search/">Search</a> </div> <div id="login"> <a href="/login/?next=">Login</a> </div> </div><!--header--> <div id="sidebar"> </div><!--sidebar--> <div id="content"> </div><!--content--> <div id="footer"> </div><!--footer--> </div><!--wrapper--> </body> HTML:
When you say: "but the result is not what I expected (some kind of wrapping occurs)" What browser is this in, and what is happening exactly. I can't see no direct problems, other than you need to contain your floats in the header, so you won't see a background colour appearing in the header until you do this. You can do this by adding overflow:auto; to the #header. Also i'd move the comments like <!--header--> before the </div> rather than after it, because if I remember right from other posts this could trip some sort of IE bug.
I'm using iceweasel (firefox) 3.0.6. Here's what I get: The sidebar comes between the nav menu and the login/logout. Since both the nav menu and the login/logout are in the header container, I would expect the sidebar to stay below... Any suggestion? thanks
Thanks for your help. Meanwhile I've found good explanations there: http://css-tricks.com/all-about-floats/