Search code examples
htmlcsstwitter-bootstrapnavbar

Navbar collapse is not working in Bootstrap


@Bhanu pratap solved the problem. check it out at the end of this question.

I've been following an old course to build a navbar collapse (sandwich). The problem is the page in the course appears to have a black bar on top and navbar appears when shrinking the page. For me, I just get a button on the left. Also, when I shrink the page I don't get the navbar.

here is the source code:

<!DOCTYPE html>
<html lang="arabic">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="description" content="">

    <meta name="author" content="">

    <link rel="icon" herf="assets/img/favicon.ico">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="assets/js/jquery-3.1.1.min.js"></script>
    <script src="assets/js/main.js"></script>

    <!-- Bootstrap core CSS -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font-Awesome icons-->
    <link href="assets/css/font-awesome/css/font-awesome.min.css">

    <!-- Google Fonts LATEEF -->
    <link href="https://fonts.googleapis.com/css?family=Changa:400,600&amp;subset=arabic,latin-ext" rel="stylesheet">

    <title>Bootstrap to Wordpress</title>




        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

  </head>

  <body>

    <!-- HEADER -->
    <header class="site-header" role="banner">

         <!-- NAVBAR -->
         <div class="navbar-wrapper">
             <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">

                  <div class="container">
                      <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                            <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" herf="/"><img src="assets/img/logo.png" alt="Bootstrap to WordPress"></a>
                      </div><!-- navbar-header -->
                      <div class="navbar-collapse collapse">

                      </div><!-- collapse nav-->
                  </div><!-- container -->

             </div><!-- navbar -->


         </div><!-- navbar-wrapper-->


    </header>

    <!-- FOOTER TAG -->
    <footer>

    </footer>

    <!-- MODAL -->
    <div>

    </div>

    <!-- BOOTSTRAP CORE JAVASCRIPT
          PLACED AT THE END OF THE DOCUMENT SO THE PAGES
          LOAD FASTER!
    ================================================== -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="assets/js/jquery-3.1.1.min.js"></script>
    <script src="assets/js/main.js"></script>

    <!-- Type google font -->
    <script src="https://use.typekit.net/byz5vqz.js"></script>
    <script>try{Typekit.load({ async: true });}catch(e){}</script>

  </body>
</html>

I tried to change this part with another source code, yet the problem occurs again.

 <!-- NAVBAR -->
             <div class="navbar-wrapper">
                 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">

                      <div class="container">
                          <div class="navbar-header">
                            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                                <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" herf="/"><img src="assets/img/logo.png" alt="Bootstrap to WordPress"></a>
                          </div><!-- navbar-header -->
                          <div class="navbar-collapse collapse">

                          </div><!-- collapse nav-->
                      </div><!-- container -->

                 </div><!-- navbar -->
            </div><!-- navbar-wrapper-->

UPDATE: @Bhanu pratap solved the propblem by addin ul and li to show the visible effects. here is his source code:

<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>


<div class="navbar-wrapper">
        <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">

            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                        <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" herf="/"><img src="assets/img/logo.png" alt="Bootstrap to WordPress"></a>
                </div><!-- navbar-header -->
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href="">First Menu Item</a>
                        </li>
                        <li>
                            <a href="">Second Menu Item</a>
                        </li>
                        <li>
                            <a href="">Third Menu Item</a>
                        </li>
                    </ul>
                </div><!-- collapse nav-->
            </div><!-- container -->

        </div><!-- navbar -->
    </div>

Solution

  • Try this.. i have just added ul and li to your code to show visible effect you can use your code section there..

    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
    
    
    <div class="navbar-wrapper">
            <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                            <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" herf="/"><img src="assets/img/logo.png" alt="Bootstrap to WordPress"></a>
                    </div><!-- navbar-header -->
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav">
                            <li>
                                <a href="">First Menu Item</a>
                            </li>
                            <li>
                                <a href="">Second Menu Item</a>
                            </li>
                            <li>
                                <a href="">Third Menu Item</a>
                            </li>
                        </ul>
                    </div><!-- collapse nav-->
                </div><!-- container -->
    
            </div><!-- navbar -->
        </div>