I am currently trying to make my navbar sticky when I scroll down, however, it isn't working. I have tried to use W3 Schools way and have tried position: sticky
on my #nav
element. I want my navbar to stay at the top of the screen when scrolling.
#nav {
width: 100%;
margin: 0;
padding-top: 5px;
text-align: center;
list-style: none;
overflow: hidden;
background-color:rgba(255, 255, 255, 0.171);
}
#nav li {
display: inline-block;
text-align: center;
padding-top:2px;
text-align: center;
padding-bottom:8px;
margin-left:20px;
}
#nav li a {
display: block;
text-decoration: none;
text-align: center;
font-weight: 600;
text-align: center;
color: black;
font-family: 'Open Sans';
margin-right:50px;
margin-left: 35px;
padding: 8px;
}
#nav li a:hover {
color: rgb(29, 57, 179);
text-align: center;
background-color: rgba(226, 226, 226, 0.637);
transition: ease-in-out;
transition-duration: 0.2s;
}
<div id="nav">
<li><a href="#">Home</i></a></li>
<li><a href="#">About Us</a></li>
<img width="50px" height="45px" text-align="center" src="file:///C:/Users/trist/Downloads/camera.svg">
<li><a href="#">Our Services</a></li>
<li><a href="#">Contact</a></li>
</div>