admin管理员组文章数量:1323732
I tried to implement a vertical navigation with twitter bootstrap 3.0 that collapses automatically.
The basics work (window size small = menu at the top like it should be), but the problem is that it is not collapsed as it is if I use the default navbar features in bootstrap.
<div class="container-fluid">
<div class="row">
<div class="navbar-brand">
<a href="<g:createLink uri="/" absolute="true" />">BABSI</a>
</div>
<button type="button" class="btn navbar-btn" data-toggle="collapse"
data-target="#sidebar">TOOGLE
Toggle navigation
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="row">
<header id="sidebar" class="col-md-2 collapse">
<div class="row">
<!-- generates ul structure -->
<nav:primary class="nav navbar-inverse nav-stacked" />
</div>
</header>
<section id="content" class="col-md-10">
<div class="row"></div>
<div class="panel panel-default">
<div class="panel-heading">
<g:layoutTitle />
</div>
<div class="panel-body">
<g:layoutBody />
</div>
</div>
</section>
</div>
</div>
I tried to implement a vertical navigation with twitter bootstrap 3.0 that collapses automatically.
The basics work (window size small = menu at the top like it should be), but the problem is that it is not collapsed as it is if I use the default navbar features in bootstrap.
<div class="container-fluid">
<div class="row">
<div class="navbar-brand">
<a href="<g:createLink uri="/" absolute="true" />">BABSI</a>
</div>
<button type="button" class="btn navbar-btn" data-toggle="collapse"
data-target="#sidebar">TOOGLE
Toggle navigation
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="row">
<header id="sidebar" class="col-md-2 collapse">
<div class="row">
<!-- generates ul structure -->
<nav:primary class="nav navbar-inverse nav-stacked" />
</div>
</header>
<section id="content" class="col-md-10">
<div class="row"></div>
<div class="panel panel-default">
<div class="panel-heading">
<g:layoutTitle />
</div>
<div class="panel-body">
<g:layoutBody />
</div>
</div>
</section>
</div>
</div>
Share
Improve this question
asked Sep 10, 2013 at 15:10
MaddisMaddis
6451 gold badge9 silver badges19 bronze badges
2 Answers
Reset to default 3You need the .navbar-collapse
class in your nav since that's the one that is set up to collapse at the given breakpoint.
I made some changes in your markup to acmodate that and also added a .navbar
container so you can easily use the .navbar-toggle
class on the button:
<div class="container">
<div class="navbar navbar-default">
<div class="navbar-brand">
<a href="#">BABSI</a>
</div>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#sidebar .navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="row">
<header id="sidebar" class="col-md-2">
<div class="collapse navbar-collapse">
<!-- generates ul structure -->
<nav:primary class="nav navbar-inverse nav-stacked" />
</div>
</header>
<section id="content" class="col-md-10">
<div class="row"></div>
<div class="panel panel-default">
<div class="panel-heading">
<g:layoutTitle />
</div>
<div class="panel-body">
<g:layoutBody />
</div>
</div>
</section>
</div>
</div>
To remove unwanted styles and since you're not using the default navbar-collapse structure you need to add this to your CSS
//remove background and border from navbar
.navbar-default{
background: none;
border: 0;
}
.navbar-collapse{
padding: 0;
}
//override width:auto of navbar-collapse
@media (min-width:768px) {
.navbar-collapse {
width: 100%;
}
}
Here's a demo fiddle with the changes
Try this.
<script>
$('.navbar-collapse a').click(function(){
$(".navbar-collapse").collapse('hide');
});
</script>
本文标签: javascriptBootstrap menu is not collapsed by default in mobile viewStack Overflow
版权声明:本文标题:javascript - Bootstrap menu is not collapsed by default in mobile view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116642a2421497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论