导航栏在小屏幕下不起作用

问题描述 投票:0回答:2

我使用引导程序创建了一个简单的导航栏,但是当我单击它时,它不显示列表项,它在更大的屏幕上工作正常。 我尝试了很多替代方案,但都不起作用。

<html>
    <head>
        <meta charset = "utf8">
        <meta http-equiv = "X-UA-Compatible" content = "IE = edge">
        <meta name = "viewport" content = "width = device-width initial-scale = 1">

        <link rel = "stylesheet" type = "text/css" href = "conFusion/css/bootstrap.min.css">
        <link rel = "stylesheet" type = "text/css" href = "conFusion/css/bootstrap-theme.min.css">
    </head>
    <body>
        <nav class = "navbar navbar-inverse" role = "navigation">

            <div class = "container">
                <div class = "navbar-header">
                    <button type = "button" class = "navbar-toggle collapsed"
                            data-toggle = "collapse" data-target = "#navbar" area-controls = "navbar" 
                            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>

                    <a class = "navbar-brand">Indore Medical</a>
                </div>
                <div id = "navbar" class = "navbar-collapse collapse">
                    <ul class = "nav navbar-nav">
                        <li class = "active"><a href = "#">Main-Course</a></li>
                        <li><a href = "#">Starters</a></li>
                        <li><a href = "#">Desert</a></li>
                        <li><a href = "#">About-us</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </body>
</html>
html twitter-bootstrap css twitter-bootstrap-3
2个回答
2
投票

考虑到您提供的代码,似乎您尚未包含 jQuery 库文件,并且 Bootstrap 的 JavaScript 需要 jQuery 来运行其 JS/jQ 事件,例如 toggle menu 等。

代码片段

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse" role="navigation">

  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" area-controls="navbar" 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>

      <a class="navbar-brand">Indore Medical</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Main-Course</a>
        </li>
        <li><a href="#">Starters</a>
        </li>
        <li><a href="#">Desert</a>
        </li>
        <li><a href="#">About-us</a>
        </li>
      </ul>
    </div>
  </div>
</nav>


0
投票

包含 Bootstrap javascript 文件。如果您已经包含 bootstrap.bundle.min.js(其中包含 Bootstrap 的 JavaScript 和必要的 Bootstrap JavaScript 插件),则无需单独包含 bootstrap.min.js。 bootstrap.bundle.min.js 包含 Bootstrap 组件和 JavaScript 功能所需的一切,包括导航栏切换器功能。

© www.soinside.com 2019 - 2024. All rights reserved.