gpt4 book ai didi

html - Bootstrap 在中心对齐导航栏

转载 作者:行者123 更新时间:2023-11-28 15:06:59 24 4
gpt4 key购买 nike

我将品牌放在中央导航栏上,我希望导航到左侧,导航到右侧。所有这些都很好,但我有疑问如何像下面的屏幕截图那样对齐左右导航中心。 enter image description here

这是我的代码:

.navbar {
position: relative;
height:150px;
}
.brand {
position: fixed;
top: 23%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
margin-left: -50px !important; /* 50% of your logo width */
display: block;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="brand" style="margin: 0; float: none;" href="#">
<img src="img/profile.png" width="250" />
</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Почетна</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">О нама</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Мени</a>
</li>
</ul>


<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Прославе</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Галерија</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Локација</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Контакт</a>
</li>
</ul>
</div>
</nav>

最佳答案

您好,您可以尝试这样做来实现您想要的效果。

首先删除类.mr-auto在你的 <ul class="navbar-nav">然后添加

一类.custom-css<div class="collapse navbar-collapse custom-css" id="navbarSupportedContent">.navbar-collapse已设置为 display:flex , 我们现在只需设置 justify-content: space-around;.custom-css

请看下面的代码。

.navbar {
position: relative;
height:150px;
}
.brand {
position: fixed;
top: 23%;
left: 50%;
/* bring your own prefixes */
transform: translate(-50%, -50%);
margin-left: -50px !important; /* 50% of your logo width */
display: block;
}

.custom-css{
justify-content: space-around;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="brand" style="margin: 0; float: none;" href="#">
<img src="img/profile.png" width="250" />
</a>
<div class="collapse navbar-collapse custom-css" id="navbarSupportedContent">

<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Почетна</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">О нама</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Мени</a>
</li>
</ul>


<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Прославе</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Галерија</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Локација</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Контакт</a>
</li>
</ul>
</div>
</nav>

希望对你有帮助

关于html - Bootstrap 在中心对齐导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49195028/

24 4 0