我遇到了bootstrap导航栏的问题。
我使用navbar-static-top制作了菜单 - 起初它一切都很好。当菜单被扩展并且添加了少量项目,并且现在具有之前要折叠的宽度时,它将分散成两行看起来很糟糕。在CSS bootstrap'a深入挖掘,但没有太大的成功。请帮忙,怎么来这里?
目前看起来如下所示:
Navbar代码:
<div class="navbar-wrapper">
<div class="container">
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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="bright-logo-text navbar-brand" href="index.html">Clipboard Stripper</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Features<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="features.html">Features</a></li>
<li><a href="screenshots.html">Screenshots</a></li>
<li class="active"><a href="usage.html">Usage</a></li>
</ul>
</li>
<li><a href="features.html">Features</a></li>
<li><a href="screenshots.html">Screenshots</a></li>
<!--li class="active"><a href="usage.html">Usage</a></li-->
<li><a href="download.html">Download</a></li>
<li><a href="purchase.html">Purchase</a></li>
<!--li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</li-->
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="contact.html">Contact</a></li>
<li> </li>
</ul>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:12)
我还希望通过CSS使用它而无需重新加载和自定义Bootstrap,Skelly
答案在Bootstrap 3
上运行正常但在我的情况下Bootstrap 3.2
CSS改变了一个小问题...这里是所有CSS所需的更新版本
@media (max-width:992px){
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
答案 1 :(得分:10)
使用CSS媒体查询可以让它更快崩溃。默认断点是768px。在这里,我们将其更改为990像素,以便在2行包装开始之前折叠..
@media (max-width: 990px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
}