Reputation: 656
I have a fixed header implemented in my CSS but for some reason, it's overlaying the browser's scroll bar. I'm not sure why it's doing this but it seems like everything else I change doesn't help. Any idea?
HTML:
<header class="clearfix"> test </header> <div id="wrapper"> <div id="content"> Content </div><!-- end #content --> </div><!-- end #wrapper --> <div id="footer"> <center>footer</center> </div>
CSS:
<style type="text/css"> * { margin:0; padding:0; } html, body { height:100%; overflow:auto; background:#2f3742; color: #B8C2CB; } #wrapper { min-height:100%; width:600px; margin: -30px auto; background:#47535e; border: 1px solid #3D4857; border-bottom: 0; } * html #wrapper { height:100%; } #content { margin-top: 100px; padding: 5px; } header { height: 70px; padding: 22px 25px; background: #18232f; text-align: center; position: absolute !important; width: 100%; z-index: 1; top:0; left:0; } #footer { height:30px; width:600px; margin: 25px auto 0; background:#2F3742; border: 1px solid #3D4857; border-top: 1px solid #2F3A4A; } </style>
Upvotes: 5
Views: 13652
Reputation: 316
Short Answer: the scrollbar is on your body, so add a margin-top to your body and your scrollbar (along with the rest of the top of your content will reappear).
body {
margin-top:110px;
}
Fixed JSFiddle: http://jsfiddle.net/9CkNC/1/
Long Answer: Note that other problems arise after this fix is made. There are a bunch of little tweaks that might be useful to make in your CSS, and I've added a bunch of comments that should help a little in the JSFiddle. Also, making a static header bar is a very common technique in the web design world, so there are a lot of great blog posts about it. I would do some snooping to see how other people have done it.
This is a great one to start with: https://www.youtube.com/watch?v=3I2Uh-D-lzI
Upvotes: 2
Reputation: 935
Three things i observe in your code:
You have giving padding in your header with 100% width
Giving body
overflow:auto
Giving
position:absolute
instead ofposition:fixed
for fixing the header
CSS WILL BE:
* {
margin:0; /* zero out margin */
padding:0; /* zero out padding */
}
html, body {
height:100%; /* gives layout 100% height */
background:#2f3742;
color: #B8C2CB;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
}
#wrapper {
min-height:100%; /* gives layout 100% height */
width:600px; /* centered div must be given a width */
margin: -30px auto; /* centers #wrapper */
background:#47535e;
border: 1px solid #3D4857;
border-bottom: 0;
}
* html #wrapper {
height:100%; /* IE6 treats height as min-height */
}
#content {
margin-top: 100px;
padding: 5px;
}
p {
font-size:1.8em;
text-align:center;
padding:30px 0 30px; /* bottom padding clears the #footer */
}
#header {
height:70px;
width:600px; /* centered div must be given a width */
/* margin: 0 auto -70px; */ /* -80px sucks it back in & auto centers it */
background-color:#18232f;
/* background-color:#2F3742; */
position: absolute;
top: 0;
border-bottom: 1px solid #2F3A4A;
}
header {
height: 70px;
padding: 0px;
background: #18232f;
text-align: center;
position: absolute !important;
width: 100%;
z-index: 1;
top:0;
left:0;
}
.inner-header { padding:20px 25px; }
#footer {
height:30px;
width:600px; /* centered div must be given a width */
margin: 25px auto 0; /* -80px sucks it back in & auto centers it */
background:#2F3742;
/* bottom: 0; */
border: 1px solid #3D4857;
border-top: 1px solid #2F3A4A;
}
HTML :
<header class="clearfix">
<div class="inner-header">
test
</div>
</header>
<div id="wrapper">
<div id="content">
Content
</div><!-- end #content -->
</div><!-- end #wrapper -->
<div id="footer">
<center>footer</center>
</div>
Upvotes: 3