Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap collapse menu disappears when resizing screen

I used bootstrap menu for my app. It looks like this: menu ok but when I change window size to smaller, it disappears - looks like this: menu disappears It disappears when its about ~965px wide (so its probably 979px). I tried this solution, didnt work. May be I'm mixing bootstrap 2 and 3? This is my menu code:

<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="brand" href="/">Digrin</a>
            <div class="nav-collapse collapse">
                <ul class="nav">
                {{ request.path  }}
                    <li{% block nav_stocks %}{% endblock %}><a href="/stocks/">Stocks</a></li>
                    <li{% block nav_mystocks %}{% endblock %}>
                    <a href="/stocks/mystocks">My Portfolio</a></li>
                    <li{% block nav_watchstocks %}{% endblock %}>
                        <a href="/stocks/watchstocks">Watcher</a></li>
                    {% if not user.is_authenticated %}
                    <li class="active"><a href="/accounts/login/?next=/stocks/">Login</a></li>
                    <li><a href="/accounts/register/">Register</a></li>
                    {% else %}
                    <ul class="nav">
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                {{ user.username }}
                                <i class="caret"></i>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="/accounts/password/change/">Change password</a></li>
                                {% if user.is_staff %}<li><a href="/admin">Admin</a></li>{% endif %}
                                <li><a href="/accounts/logout/?next=/stocks/">Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                    {% endif %}
                </ul>
            </div><!--/.nav-collapse -->
        </div>
    </div>
</div>

includes:

<meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <!-- Le styles -->
    <link href="{% static "css/bootstrap.css" %}" rel="stylesheet">
    <style>
        body {
            padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
        }
    </style>
    <link href="{% static "css/bootstrap-responsive.css" %}" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="{% static "js/jquery-1.8.1.min.js" %}" type="text/javascript"></script>
    <script src="{% static "js/bootstrap.min.js" %}" type="text/javascript"></script>

And site (far from finished) If I zoom in, menu disappears as well.

like image 390
Lucas03 Avatar asked Nov 26 '13 14:11

Lucas03


1 Answers

If you do not want your navbar links to be collapsed on smaller devices, then you need to remove the <div class="nav-collapse collapse"> element.

The basic structure should look something like this....

<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <a class="brand" href="#">Title</a>
    <ul class="nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
    </ul>
  </div>
</div>

If you want to keep the responsive functionality, then add the below code to within you container div. This will give you a button to toggle the collapsed menu on smaller devices.

  <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </a>

So then the end result would look something like this.

<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">

      <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>

      <!-- Be sure to leave the brand out there if you want it shown -->
      <a class="brand" href="#">Project name</a>

      <!-- Everything you want hidden at 940px or less, place within here -->
      <div class="nav-collapse collapse">
        <!-- .nav, .navbar-search, .navbar-form, etc -->
      </div>

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

Also, you do not have to nest a <ul class="nav"> element within a <ul class="nav"> element for the dropdown menus. The correct structure for you navigation items should look like this.

<ul class="nav">
  <li class="active"><a href="#">Home</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
      Test
      <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
      ...
    </ul>
  </li>
</ul>
like image 105
Schmalzy Avatar answered Nov 01 '22 15:11

Schmalzy