I'm trying to center a navigation bar on my website. The difficulty I am having is that I do not want the navigation bar's width to take up the entire page width and I want the position of the navigation bar to be fixed.
Here's a very simple example of what I'm trying to do: https://jsfiddle.net/de83m2zL/51/
As you can see, the navigation bar is only part of the page width, but isn't centered. My question is, how can I make it centered?
div#navbar {
position: fixed;
margin: 0 auto;
width: 80%;
background-color: #0050ca;
}
div ul {
list-style-type: none;
margin: 0;
padding: 0;
}
div ul li {
display: inline-block;
margin-right: 10px;
}
div ul li a {
color: white;
}
h1 {
margin-top: 40px;
}
<div id="navbar">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/">About</a></li>
<li><a href="/">Blog</a></li>
</ul>
</div>
<br>
<h1>
Hello!
</h1>