How do I make a header cover the contents and span the entire page length? When I use this css
#header {
display: inline-block;
background-color: #015367;
}
#login {
color: #b92c2c;
font-size: 1.25em;
margin-left: 18em;
position: relative;
top: 16px;
text-decoration: none;
}
#search-form {
margin-left: 0.5em;
margin-right: 15em;
position: relative;
top: 18px;
}
.lfloat {
float: left;
}
.rfloat {
float: right;
}
with this html
<body>
<div id="header">
<div id="page-nav" class="rfloat">
<a id="login" class="lfloat" href="/login">login</a>
<form id="search-form" class="rfloat" action="search.py" method="get">
<input id="searchbox" type="text" name="q" placeholder="search"/>
</form>
</div>
</div>
</body>
I get this result (in firefox)

What do I need to change to get a proper header (like stackoverflow, facebook, etc)?
Since you used
floatfor the elements inside#header, then you only need to add this.Before overflow:hidden
Notice the black border, the
#headerisn’t wrapping the contents.After overflow:hidden
Check it out : http://jsfiddle.net/AliBassam/vpRc2/
Adjust the
topso that elements are positioned the way you like,position:relative;has no use here, just usefloatsandmargins.