Navbar无法移动

时间:2017-07-16 12:37:53

标签: html twitter-bootstrap mobile navbar

     <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
          <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar">
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
              </button>
              <img src="http://karinakozarova.me/Blog/pics/logo-kari.png" width = "90px"/>
          </div>
          <div class="collapse navbar-collapse" id="myNavbar">
              <ul class="nav navbar-nav navbar-right text-color">
                  <li><a class = "menu" href="\Blog\home.html">Home</a></li>
                  <li><a class = "menu" href="\Blog\posts.html">Posts</a></li>
                  <li><a class = "menu" href="\Blog\contact_info.html">Contact</a></li>
                  <li><a class = "menu" href="\Blog\about.html">About</a></li>
              </ul>
          </div>
      </div>
  </nav>

以下代码不适用于移动设备,在另一个SO问题中,我读到数据目标=&#34; myNavbar&#34;所以我做了但它还没有用。

1 个答案:

答案 0 :(得分:2)

您正在提供data-target个ID ...您需要在#之前使用id

设置

data-target="#myNavbar"

现在应该可以了。

&#13;
&#13;
<html lang="en">
<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script
  src="https://code.jquery.com/jquery-3.2.1.min.js"
  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

  <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
          <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
              </button>
              <img src="http://karinakozarova.me/Blog/pics/logo-kari.png" width = "90px"/>
          </div>
          <div class="collapse navbar-collapse" id="myNavbar">
              <ul class="nav navbar-nav navbar-right text-color">
                  <li><a class = "menu" href="\Blog\home.html">Home</a></li>
                  <li><a class = "menu" href="\Blog\posts.html">Posts</a></li>
                  <li><a class = "menu" href="\Blog\contact_info.html">Contact</a></li>
                  <li><a class = "menu" href="\Blog\about.html">About</a></li>
              </ul>
          </div>
      </div>
  </nav>
</body>
</html>
&#13;
&#13;
&#13;