Thomas Allen
Thomas Allen

Reputation: 811

Navbar not collapsing

I have these in my header rather than under the body as it said bootstrap needs jQuery to run:

<script   src="https://code.jquery.com/jquery-3.1.0.min.js"   integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="   crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

And this is the actual navbar part. I'm pretty sure something is missing but can't see what i'm doing wrong:

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">     
            <button type="button" class="navbar-toggle collapsed navbar-right " data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </div>
          </button>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
            <div class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    <li id="button0"><a href="#landing-page">Home</a></li>
                    <li id="button1"><a href="#what-we-do">What We Do</a></li>
                    <li  id="button2"><a href="#contact">Contact Us</a></li>
                    </div>
                 </ul>
            </div>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

Upvotes: 0

Views: 114

Answers (4)

Jason
Jason

Reputation: 11

Remove the div on line 17 and its closing tag. Also, remove the extra closing divs on line 11 and 22.

<nav class="navbar navbar-default navbar-fixed-top">

    <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">     
            <button type="button" class="navbar-toggle collapsed navbar-right " data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>

            </button>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">

            <ul class="nav navbar-nav">
                <li id="button0"><a href="#landing-page">Home</a></li>
                <li id="button1"><a href="#what-we-do">What We Do</a></li>
                <li  id="button2"><a href="#contact">Contact Us</a></li>
            </ul>

        </div><!-- /.navbar-collapse -->

    </div><!-- /.container-fluid -->

</nav>

Upvotes: 0

Anil  Panwar
Anil Panwar

Reputation: 2622

You have added two div with navbar-collapse collapse classes, remove the inner one before ul.

See Demo

 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">     
            <button type="button" class="navbar-toggle collapsed navbar-right " data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>                
          </button>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
         
                 <ul class="nav navbar-nav">
                    <li id="button0"><a href="#landing-page">Home</a></li>
                    <li id="button1"><a href="#what-we-do">What We Do</a></li>
                    <li  id="button2"><a href="#contact">Contact Us</a></li>
                   
                 </ul>
        
     
    </div><!-- /.container-fluid -->
</nav>

Upvotes: 0

Lalji Tadhani
Lalji Tadhani

Reputation: 14149

HTML Some Unwanted div change HTML

<nav class="navbar navbar-default navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed navbar-right " data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>

                </button>
            </div>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav">
                    <li id="button0"><a href="#landing-page">Home</a></li>
                    <li id="button1"><a href="#what-we-do">What We Do</a></li>
                    <li id="button2"><a href="#contact">Contact Us</a></li>

                </ul>
            </div>
        </div>

    </nav>

https://jsfiddle.net/o6p71fko/1/

Upvotes: 1

Hugo G
Hugo G

Reputation: 16484

  1. do not include jQuery twice (you have version 3.1.0 and 1.8.3)
  2. Include bootstrap CSS
  3. Include bootstrap-collapse plugin: https://getbootstrap.com/javascript/#collapse

Upvotes: 0

Related Questions