在bootstrap 3中,我有一个带有表单栏的导航栏。
我尝试在搜索按钮的右侧添加另一部分。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-sm-12">
<nav role="navigation" class="navbar navbar-default pull-right">
<div class="container-fluid">
<form class="navbar-form" role="search">
<div class="checkbox">
<label>
<input type="checkbox" id="inactiveLodger">Locataire inactif</label>
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button id="lodgerSearch" type="button" class="btn btn-default"><i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"> <a href="#" id="username" class="dropdown-toggle" data-toggle="dropdown">Paul Smith<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="glyphicon glyphicon-lock"></i> Changer mot de passe</a>
</li>
<li id="logout"><a href="#"><i class="glyphicon glyphicon-log-out"></i>Déconnexion</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
现在,另一部分在下面,就像你在图像上看到的一样。
答案 0 :(得分:0)
如果您想使用float:right
所做的navbar-right
,只需颠倒表单和下拉菜单的顺序即可。右浮动元素必须放在其他人之前,以便让其他人浮在他们周围。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-sm-12">
<nav role="navigation" class="navbar navbar-default pull-right">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"> <a href="#" id="username" class="dropdown-toggle" data-toggle="dropdown">Paul Smith<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="glyphicon glyphicon-lock"></i> Changer mot de passe</a>
</li>
<li id="logout"><a href="#"><i class="glyphicon glyphicon-log-out"></i>Déconnexion</a>
</li>
</ul>
</li>
</ul>
<form class="navbar-form" role="search">
<div class="checkbox">
<label>
<input type="checkbox" id="inactiveLodger">Locataire inactif</label>
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button id="lodgerSearch" type="button" class="btn btn-default"><i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</div>
</nav>
</div>
答案 1 :(得分:0)
除非您对navbar
应用其他更改,否则您不需要应用的额外课程(col-sm-12 / pull-right / etc)。只需使用默认的类和结构,然后重新排序右浮动导航元素,使它们按照您想要的顺序排列。
参见示例。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
<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" aria-expanded="false"> <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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a>
</li>
<li><a href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> Paul Smith <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="glyphicon glyphicon-lock"></i> Changer mot de passe</a>
</li>
<li><a href="#"><i class="glyphicon glyphicon-log-out"></i> Déconnexion</a>
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" id="inactiveLodger">Locataire inactif</label>
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Rechercher" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button id="lodgerSearch" type="button" class="btn btn-default"><i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</div>
</form>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>