I have a navigation bar that has a fixed position. Now the rest of my content gets put below this navigation bar since the position of that bar is fixed. How can I position the rest of my content below my fixed navigation bar?
https://gyazo.com/dad3fc7fc35e65a4ad73fd0da2c6ffa7 As you can see a part of my content disappears below my fixed navigation bar.
<div class="header" id="header">
<div class="menu1" id="menu1">
<div class="name">Jan de Sterke</div>
<div class="menu_item_holder">
<div class="menu_item"><a href="index.php">Home</a></div>
<div class="menu_item"><a href="sco.php">SCO</a></div>
<div class="menu_item"><a href="uex.php">UEX</a></div>
<div class="menu_item"><a href="dev.php">DEV</a></div>
</div>
</div>
</div>
CSS
.header {
width: 100%;
background: #1C2023;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: fixed;
top: 0;
bottom: 0;
padding: 2.5% 0 2.5% 0;
transition: all 0.5s;
}
De div below my navigation bar is a colored line.
CSS for this line:
.headerpic {
width: 100%;
height: 5px;
background: #fc4a1a;
}
I have tried to use the following JavaScript code to fix the problem, but it is not working.
let heightvalue = document.getElementById('header').offsetHeight;
let content = document.getElementById('headerpic');
content.style.marginTop = heightvalue + "px";
My JavaScript code is actually working.
let heightvalue = document.getElementById('header').offsetHeight;
let content = document.getElementById('headerpic');
content.style.marginTop = heightvalue + "px";
I don't know why it wasn't working before. Next problem is that this margin-top value needs to be re-calculated everytime the window gets resized. Currently it calculates a value and sets it as a margin-top at the beginning of the loading. When I resize the window this same value stays there, which causes blank spaces to appear.
EDIT: This problem can be solved by rerunning the code on the window resize event. (JavaScript window resize event) The code for my page is:
window.onresize = function(event) {
let heightvalue = document.getElementById('header').offsetHeight;
let content = document.getElementById('headerpic');
content.style.marginTop = heightvalue + "px";
};