So i tried everything for the header to be always on top of the viewport. I’ve tried the most obvious way which is to use the position: fixed
in the header. But that made the nav-bar goes to the left when its supposed to be on the right. So I improvised. And the nav-bar and image manage to stay on top. But why is the tester on codepen says that the nav-bar hasn’t stay on top.
header{
position: relative;
padding: 10px 10px;
display: flex;
justify-content: space-between;
z-index: 100;
}
#header-img{
border-color: black;
width: 30px;
height: auto;
z-index: 100;
position: fixed;
}
#nav-bar{
text-align: right;
position: fixed;
align-items: right;
margin-left: 900px;
<header id="header">
<img id="header-img"
src="pen-bakery.png"/>
<nav id="nav-bar">
<a class="nav-link" href="#bread">Breads</a>
<a class="nav-link" href="#made" >How Its Made</a>
<a class="nav-link" href="#price" >Price</a>
</nav>
</header>