Can someone help me fix my navbar so that it remains fixed when I scroll? Currently, it moves up as I scroll down. Below are the source codes I'm using:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1 {
margin: 1rem;
}
ul {
position: fixed;
width: 100vw;
padding-top: 5px;
list-style-type: none;
background-color: #333333;
height: 40px;
}
li {
display: block;
float: left;
font-size: 1.25rem;
}
a {
text-decoration: none;
color: white;
padding: 12px;
}
a:hover:not(.home) {
background-color: #111111;
}
.home {
background-color: #04aa6d;
}
main {
position: absolute;
top: 40px;
background-color: #1abc9c;
width: 100vw;
}
<body>
<header>
<ul>
<li><a class="home" href="">Home</a></li>
<li><a href="">News</a></li>
<li><a href="">Contact</a></li>
<li><a href="">About</a></li>
</ul>
</header>
<main>
<h1>Fixed Top Navigation Bar</h1>
<p>Abdul Alim loves to cultivate crops and travel. Wanna hear a story?</p>
<p>Abdul Alim loves to cultivate crops and travel. Wanna hear...;
I need help fixing the header/navbar content to remain fixed while scrolling. I'm new to HTML/CSS, so detailed explanations would be greatly appreciated. Thanks, Abdul Alim