我有一个导航栏,我想将我的搜索字段放在中心,但我找不到我应该使用的课程。除官方网站外还有其他文件吗?我会列出所有课程以及他们做什么,这是不可能的?
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">PrivateChat</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Pseudo <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Profil</a></li>
<li class="divider"></li>
<li><a href="#">Déconnexion</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
答案 0 :(得分:5)
以下是我修改后的答案:
.navbar-center
{
position: absolute;
width: 100%;
text-align: center;
margin: auto;
}
并且
<form class="navbar-form navbar-center" role="search">
答案 1 :(得分:0)
如果您使用的是Bootstrap 4,则可以这样简单地完成操作
<form class="navbar-form d-flex justify-content-center w-100" role="search"></form>
这也等效于此:
.navbar-center {
display:flex;
justify-content:center;
width: 100%;
}