Bootstrap 4示例
Bootstrap 3示例
如何在Bootstrap 3中获取Bootstrap 4菜单?
此代码来自bootstrap 4 http://v4-alpha.getbootstrap.com/examples/navbar/:
<div class="container">
<nav class="navbar navbar-light bg-faded">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#navbar-header" aria-controls="navbar-header">
☰
</button>
<div class="collapse navbar-toggleable-xs" id="navbar-header">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
<form class="form-inline pull-xs-right">
<input class="form-control" type="text" placeholder="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav> <!-- /navbar -->
</div><!-- /container -->
答案 0 :(得分:2)
你需要在bootstrap 4中添加一些css,我想他们这样做是因为你可以切换不同大小的菜单,所以你需要将媒体查询添加到你希望菜单打开的任何大小。像这样:
这是一个小提琴,其中包含一些自定义样式,用于引导4导航栏Bootstrap 4 Navbar Fiddle
@media(max-width:33.9em) {
.navbar .collapse {max-height:250px;width:100%;overflow-y:auto;overflow-x:hidden;}
.navbar .navbar-brand {float:none;display: inline-block;}
.navbar .navbar-nav>.nav-item { float: none; margin-left: .1rem;}
.navbar .navbar-nav {float:none !important;}
.nav-item{width:100%;text-align:left;}
.navbar .collapse .dropdown-menu {
position: relative;
float: none;
background:none;
border:none;
}
}