This issue of header or navbar positioning is a common one that many websites face.
The problem arises when using the position: fixed
property, as it takes the element out of the document flow, causing elements below it to be hidden behind.
One solution is to add a margin-top
property to the section following the header, pushing it down.
Alternatively (and the recommended approach) is to use position: sticky
on the header instead of position: fixed
. This will provide similar functionality without removing the element from the document flow.
The revised code snippet would appear as follows:
header{
position: sticky;
top: 0;
left: 0;
width: 100%;
padding: 25px 40px ;
display: flex;
justify-content: space-between;
align-items: center;
}
<header>
<a href="#" class="logo">Logo</a>
<ul>
<li>List Item</li>
</ul>
</header>
<section>
Section Area
</section>
If you're interested in learning more about this topic, Kevin Powell has written an informative article - check it out here: