Bootstrap崩溃不起作用;汉堡菜单没有出现

时间:2015-08-18 19:53:46

标签: jquery twitter-bootstrap

我正在制作一个Angular应用程序,并在Bower上安装了所有的lib。当我检查控制台时,所有工作表/脚本都正确加载。我也有自己的bootstrap和jQuery定义。我复制了Bootstrap网站的代码。

我遇到的问题是汉堡菜单永远不会出现。链接只是保持与屏幕大时完全相同。另一个问题是,即使站点很大,导航崩溃崩溃div也不会显示出来。似乎崩溃存在问题,这使两者都无法正常工作。建议?

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jay - Web Developer</title>

    <!-- For Angular Routing -->
    <base href='/'>

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

    <!-- JS -->
    <script src="assets/libs/angular/angular.min.js"></script>
    <script src="assets/libs/angular-route/angular-route.min.js"></script>
    <script src="assets/libs/angular-animate/angular-animate.min.js"></script>
    <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.js"></script>

    <!-- APP -->
    <script src="app/controllers/mainCtrl.js"></script>
    <script src="app/app.routes.js"></script>
    <script src="app/app.js"></script>
</head>

<body ng-app="jayPortfolio" ng-controller="mainController as main">

  <!-- NAVBAR -->
  <header>
    <div class="navbar navbar-default">
      <div class="navbar-inner">
          <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
              <span class="icon-bar">About</span>
              <span class="icon-bar">Portfolio</span>
              <span class="icon-bar">Experience</span>
              <span class="icon-bar">Contact</span>
            </a>

            <a class="brand" href="#">JAY</a>

            <div class="nav-collapse collapse">
              work please
            </div>

          </div>
       </div>
    </div>
  </header>
</body>

</html>

5 个答案:

答案 0 :(得分:8)

导航栏的标记不正确。标记应如下:

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <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" href="#">Huisje Thuisje</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#contact">Contact</a></li>
                <!-- Put here your menu items -->
            </ul>

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

ul元素中,放置菜单项。这应该够了吧。另请参阅documentation page

答案 1 :(得分:0)

container部分的语法更像是这样:

<div class="container">
        <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>

        <a class="brand" href="#">JAY</a>

        <div class="nav-collapse collapse">
          <ul class="nav navbar-nav">
             <li><a href="#">About</a></li>
             <li><a href="#">Portfolio</a></li>
             <li><a href="#">Experience</a></li>
             <li><a href="#">Contact</a></li>
          </ul>
        </div>

</div>

答案 2 :(得分:0)

在我的情况下,我新创建的laravel项目hamburger菜单不起作用,因此转到https://getbootstrap.com/docs/4.4/getting-started/introduction/并复制3 js链接并添加到标题中。

答案 3 :(得分:0)

引导程序网站复制 Javascript 链接并将其粘贴到HTML文件中。它将正常工作!

答案 4 :(得分:0)

所以对我来说,我有同样的问题,问题是我使用的CDN是:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

对于ajax来说是必需的 这是在页脚部分 所以我把它留在这里供ajax使用,并在标头部分添加了以下脚本cdns,并且bootstrap折叠工作正常:

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>