调整大小屏幕时,引导折叠菜单消失 [英] bootstrap collapse menu disappears when resizing screen

查看:127
本文介绍了调整大小屏幕时,引导折叠菜单消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用引导菜单。它看起来像这样:

但是当我将窗口大小更改为更小,它消失了 - 看起来像这样:

当它约〜965px (所以它可能是979px)。我尝试此解决方案,没有工作。可能是我混合bootstrap 2和3?
这是我的菜单代码:

I used bootstrap menu for my app. It looks like this: but when I change window size to smaller, it disappears - looks like this: 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>

包括:

<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>

网站

推荐答案

如果你不想要您的导航栏链接会在较小的设备上折叠,那么您需要删除< div class =nav-collapse collapse> 元素。

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>

如果您想保留响应功能,请将以下代码添加到 container 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>

此外,您不必嵌套< ul class =下拉菜单的< ul class =nav> 元素中的nav> 导航项的正确结构应如下所示。

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>

这篇关于调整大小屏幕时,引导折叠菜单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆