如何在页面中心对齐整个导航?包括导航栏品牌和商品? Photo here 谢谢。
<nav class="navbar sticky-top navbar-expand-lg navbar-light ">
<a class="navbar-brand" href="home.html">
<img src="Images/logo.png" width="65" height="50" class="d-inline-block align-top">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Почетна<span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Информации</a>
<a class="nav-item nav-link" href="#">Контакт</a>
</div>
</div>
</nav>
答案 0 :(得分:0)
最简单的方法是将父级设置为100%宽度,为导航指定特定宽度并设置
margin: 0 auto
如果您正在使用bootstrep,请仔细阅读文档:
https://getbootstrap.com/docs/4.3/utilities/spacing/#horizontal-centering
答案 1 :(得分:0)
在您的CSS中:
.navbar{
Position: absolute;
Top:50%;
Right:50%;
Transform: translate (-50%,-50%)
}
所有小写字母。