菜单没有折叠

时间:2016-12-28 20:25:56

标签: html css twitter-bootstrap

我正在尝试为移动屏幕制作可折叠的导航栏。它确实崩溃并显示图标栏跨度标记;但是,当我点击它时它什么也没做。

这是我的HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="CSS/main.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <title>Home Page</title>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
    <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" style="margin-top: -15px; float: left;" href="#">
            <img alt="Brand" class="pull-left col-xs-0" style="margin-left: -15px;" src="Images/TrueInternet.png">
          </a>
        <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
        <span class="icon-bar"></span>
        </button>
        </div>
        <div class="collapse navbar-collapse navHeaderCollapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Home</a></li>
                <li><a href="#">Internet</a></li>
                <li><a href="#">Phone</a></li>
                <li><a href="#">Android TV</a></li>
                <li><a href="#">Shaw Direct</a></li>
                <li><a href="#">Contact Us</a></li>
            </ul>
    </div>  
    </div>
</nav><div class="container">
    <div class="row">
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
    </div>
</div>

</body>
</html>

我似乎无法弄明白。

1 个答案:

答案 0 :(得分:2)

您缺少元标记:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

特别是视口对于bootstrap正常工作至关重要。

你也没有实现jQuery。 在body标签的底部添加以下内容:

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>

添加元标记和脚本标记后,这应该是您的代码:

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="CSS/main.css">
  <title>Home Page</title>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
    <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" style="margin-top: -15px; float: left;" href="#">
            <img alt="Brand" class="pull-left col-xs-0" style="margin-left: -15px;" src="Images/TrueInternet.png">
          </a>
        <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
        <span class="icon-bar"></span>
        </button>
        </div>
        <div class="collapse navbar-collapse navHeaderCollapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Home</a></li>
                <li><a href="#">Internet</a></li>
                <li><a href="#">Phone</a></li>
                <li><a href="#">Android TV</a></li>
                <li><a href="#">Shaw Direct</a></li>
                <li><a href="#">Contact Us</a></li>
            </ul>
    </div>  
    </div>
</nav><div class="container">
    <div class="row">
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
        <div class="col-xs-12 col-md-1">Test.  Test.  Test.  Test.  Test.  Test.  Test.  Test.</div>
    </div>
</div>
  
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <!-- Include all compiled plugins (below), or include individual files as needed -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
&#13;
&#13;
&#13;