[英]Bootstrap nav-bar aligned center
Here's my fiddle of my html/bootstrap code. 这是我的html / bootstrap代码的小提琴 。
<body>
<h1 style="text-align:center">AntwerPay</h1>
<!--Navbar-->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">AntwerPay</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class=""><a href="#">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Gebieden
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">Gebied 1</a></li>
</ul>
</li>
<li><a href="#">Alle Gebieden</a></li>
</ul>
</div>
</div>
</nav>
</body>
As you can see in my navbar everything is aligned real nicely to the left. 如您在我的导航栏中所看到的,所有内容都很好地对齐到左侧。 This is a problem for me.
这对我来说是个问题。 I want the
navbar-brand
to be on the left, and i want the 3 other buttons to be centered. 我希望
navbar-brand
位于左侧,我希望其他3个按钮居中。 I have researched this a lot and found various .css codes but none worked for me. 我对此进行了大量研究,发现了各种.css代码,但没有一个对我有用。
You can do this using CSS, I've included a suggestion for manually adjusting the position of the items: 您可以使用CSS进行此操作,我提供了一个建议,用于手动调整项目的位置:
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
/* You'd have to adjust this whenever an item is added to the nav-bar */
margin-right: 10%;
}
.navbar .navbar-collapse {
text-align: center;
}
This has been answered already here 这已经在这里回答了
Along with your (Again) updated fiddle here 以及您(再次)更新的小提琴在这里
.navbar-bav { float: none !important; text-align:center; }
.navbar-nav > li { display:inline-block; float: none !important; }
If you do NOT know how to make the navbar responsive, then implement the codes above in a @media (min-width: 768px)
query in order not to fail the responsiveness of Bootstrap Navbar. 如果您不知道如何使导航栏响应,请在
@media (min-width: 768px)
查询中实现以上代码,以免使Bootstrap Navbar响应速度失败。
Hope this works for you: 希望这对您有用:
#myNavbar {
text-align: center;
}
.navbar-nav {
margin: 0 auto;
display: inline-block;
float: none;
}
Make shure to keep an eye on the mobile view. 请谨慎注意移动视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.