请参阅下面的代码或bootply
我对此有一些严重的问题。
我的问题:
我无法将导航栏中的所有项目完全对齐。有什么想法吗?
我不想在移动版上显示搜索字段,省略了吗?
尝试插入用于搜索的bootstrap glyphicon而不是用于搜索的css代码中的图像,但是如何在css中触发glyphicon,我可以将其设为黑色还是白色?
FILTER (lang(?label) = "en")
答案 0 :(得分:1)
对于搜索按钮,尝试使用font-awesome,它看起来会更好(有白/黑版本(http://fontawesome.io/icon/search/))
请参阅此链接:How to center navbar elements vertically (Twitter Bootstrap)? 用于垂直居中
使用此功能(将类设置为hidden-phone hidden-tablet)以删除移动设备上的搜索
<li class="hidden-phone hidden-tablet">
<form class="navbar-form navbar-left searchsite" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</li>
希望这有帮助! (如果有效,请尽量接受答案):)
答案 1 :(得分:1)
height
.navbar-right
造成的
hidden-xs
search
图标,您可以使用bootstrap已有的glyphicons。
您可以查看here
.glyphicon-search {
color: white
}
<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.6/js/bootstrap.min.js">
</script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-fixed-top my-navbar">
<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="/boyt2">Company Name</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>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a>
</li>
<li><a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a>
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left hidden-xs" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle avatar" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Username <span class="caret"></span> <img src="http://placehold.it/20x20"></a>
<ul class="dropdown-menu noshadow">
<li><a href="#">Action</a>
</li>
<li><a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a>
</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
答案 2 :(得分:1)
添加此CSS:
@media (min-width: 768px) {
.navbar .navbar-brand {
padding: 20px 15px;
}
.navbar .nav:not(.navbar-right) > li > a {
padding: 20px 15px;
}
.navbar-form {
margin-top: 14px;
}
}
navbar-right
中的图像导致导航栏高度为60px而不是默认的50px,20px填充将使元素居中。
要在移动设备上隐藏搜索栏,您可以添加课程hidden-xs
:
<form class="navbar-form navbar-left searchsite hidden-xs" role="search">
</form>