我试图在我的网页上居中导航栏。我的最小宽度为 945px,如果超过该宽度,则为屏幕的 50%。我现在希望它居中,所以我将它向左移动 50%,但随后我需要调整边距。我如何编码宽度/ 2?
#navBarImg {
position:absolute;
left:50%;
width:50%;
margin-left:-(width/2);
top:50px;
z-index:2;
min-width:945px;
}
<body>
<div id="container">
<div id="navBar">
<img id="navBarImg" src="../Navigation/navBarBGImg.png" />
<img id="navBarLogo" src="../Navigation/navBarLogo.png" />
<div id='navMenuPart1' class="navMenu">
<ul>
<li><a href='#'><span>Research</span></a></li>
<li><a href='#'><span>Team</span></a></li>
<li><a href='#'><span>News</span></a></li>
<li><a href='#'><span>Courses</span></a></li>
<li><a href='#'><span>Outreach</span></a></li>
<li><a href='#'><span>Contact</span></a></li>
</ul>
</div>
</div>
</div>
</body>
</html>