I am making a new website, and i have a problem with the header... I set the header's position to fixed, and that works but the content below the header is hidden. I tried to move the content down with margin-top: 10px
, but all it did was move the header down.
Link to jsfiddle:
http://jsfiddle.net/vwzhda41/
Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.
To fix the position of the header in the webpage, use position: fixed, and to fix it at top use to top:0. The fixed-top can overlay other elements. So to avoid it add margin-top to the other contents.
To create a fixed top menu, use position:fixed and top:0 . Note that the fixed menu will overlay your other content. To fix this, add a margin-top (to the content) that is equal or larger than the height of your menu.
Give padding-top:58px;
to the .responsiveContainer
and add top:0;
to the .header
.
Jsfiddle
.responsiveContainer {
width: 100%;
// Add padding top
padding-top: 58px;
}
.header {
background-color: #000000;
padding: 10px;
padding-left: 0;
padding-right: 0;
box-shadow: 0 5px 0 #232323;
text-align: center;
width: 100%;
position: fixed;
// Add top 0
top: 0;
}
According to MDN:
fixed
Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and don't move it when scrolled. When printing, position it at that fixed position on every page. This value always create a new stacking context.
Try to use
padding-top: 58px;/*the height of the header*/`
instead of
margin-top:10px;
You need put the <div class="header">
inside of a div with defined height, like:
<div class="heightTest">
<div class="header">
<div class="navbar">
<ul>
...
</ul>
</div>
</div>
</div>
and css:
.heightTest{height:90px;}
Jsfiddle: http://jsfiddle.net/vwzhda41/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With