I would like some help on how to make my navbar stay at the top in CSS. Technically, I am using Sass, but CSS is compatible with Sass, so anything is fine (as long as it works!).
I know this has already been asked several times, but it is usually with JavaScript or is doesn't answer the question. I have already tried using position:sticky
, but maybe I placed it in the wrong tag.
Here is the html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../../static/css/styles.css">
<title>Home</title>
</head>
<body>
<div class="navbar">
<h1>SomeCompany</h1>
<ul>
<li><a href="localhost:8000">Home</a></li>
<li><a href="localhost:8000">About</a></li>
<li><a href="localhost:8000">Products</a></li>
<li><a href="localhost:8000">Testimonials</a></li>
<li><a href="localhost:8000">Contact Us</a></li>
</ul>
</div>
</body>
</html>
Now, here is the CSS code (with me using position:sticky
in .navbar
):
body {
margin: 0; }
.navbar {
position: sticky;
padding: 1em 2em;
background-color: antiquewhite;
h1 {
margin: 0; }
ul {
position: relative;
bottom: 1em;
float: right;
li {
display: inline;
margin-right: 2em; }
}
}
Thank you in advance