I have a navigation bar which I want it to always stay centered when the window is resized. The bar is on top of a picture which serves as the background of the website. Here's the code:
<!doctype html>
<html lang="en">
<head>
<style>
body {
font-family: Trebuchet MS;
}
.containermain {
margin: auto;
}
.navibar {
z-index: 1;
position: absolute;
background-color: #000000;
border-radius: 5px;
/*text-align: center;*/
left: 200px;
right: 80px;
top:140px;
width: 870px;
/*max-width: 100%;*/
margin: auto;
}
</style>
</head>
<body style="margin:0px;">
<div class="containermain">
<img class="bg" src="bg.png" alt="background">
</div>
<div class="navibar">
<a class="button btnhome" href="x.html#home" target="_blank">home</a>
<a class="button" href="x.html#portfolio" target="_blank">portfolio</a>
<a class="button" href="x.html#blog" target="_blank">blog</a>
<a class="button" href="x.html#contact" target="_blank">contact</a>
</div>
</body>
</html>
I've tried several approach like "margin: auto", but nothing works, the navi bar is pinned to the place. Please help, thanks in advance!