简体   繁体   English

单击后的Bootstrap 3折叠菜单

[英]Bootstrap 3 collapsing menu after click

I'm having some problem with a Bootstrap menu. 我在Bootstrap菜单上遇到问题。 I want to collapse menu after clicking one of the section instead. 我想点击该部分之一后折叠菜单。

HTML: HTML:

<div class="container" id="home">
        <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <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="#home">HOME</a></li>
                        <li><a href="#philosofy">PHILOSOFY</a></li>
                        <li><a href="#knowledge">KNOWLEDGE</a></li>
                        <li><a href="#experience">EXPERIENCE</a></li>
                        <li><a href="#interests">INTERESTS</a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
</div>

I've created this fiddle: 我创建了这个小提琴:

http://jsfiddle.net/kHhgw/ http://jsfiddle.net/kHhgw/

You can utilize the data-toggle="collapse" and data-target="#bs-example-navbar-collapse-1" attributes in your link elements in addition to the menu button. 除了菜单按钮之外,您还可以在链接元素中使用data-toggle="collapse"data-target="#bs-example-navbar-collapse-1"属性。

So from your example: 所以从你的例子:

<a data-toggle="collapse" data-target="bs-example-navbar-collapse-1" href="#philosofy">PHILOSOFY</a>

Updated fiddle: http://jsfiddle.net/kHhgw/1/ 更新的小提琴: http : //jsfiddle.net/kHhgw/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM