frankcecca
frankcecca

Reputation: 149

Bootstrap 3 collapsing menu after click

I'm having some problem with a Bootstrap menu. I want to collapse menu after clicking one of the section instead.

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/

Upvotes: 0

Views: 3283

Answers (1)

MarquisDeMizzle
MarquisDeMizzle

Reputation: 514

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.

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/

Upvotes: 2

Related Questions