Bootstrap Navbar没有正确响应

时间:2017-03-19 20:07:30

标签: html twitter-bootstrap navbar

我正在尝试为FreeCodeCamp项目创建一个投资组合,并使用this video作为我的导航栏的灵感。这是CodePen显示我到目前为止所做的事情。正如您所看到的,我的导航栏的响应方式与视频中的响应方式不同,而且我没有足够的经验知道原因。视频过时了吗?他在视频中使用的方法在CodePen中不起作用吗?我错过了别的什么吗?任何反馈都非常感谢。

代码:

<script src="https://use.fontawesome.com/f42d4534b0.js"></script>
<html>
<head> 
<title>

</title>
<meta name="viewport"content="width=device-width, initial-scale=1.0">
</head>

<body>

 <div class="navbar navbar-custom navbar-fixed-top">

<div class="container">

 <a href="#" class="navbar-brand">evdanger<a>

   <button class = "navbar-toggle pull-right" data-toggle = "collapse" data-target = ".navHeaderCollapse">
     <i class = "fa fa-bars"></i> 
   </button>

   <div class = "collapse navbar-collapse navHeaderCollapse">

     <ul class = "nav navbar-nav navbar-right">

      <li class = "active"><a href = "#">Home</li>
       <li class = "dropdown">

         <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">Social Media</a>

         <ul class = "dropdown-menu">

           <li><a href = "#">Twitter</li>
           <li><a href = "#">Facebook</li>
           <li><a href = "#">Google+</li>
           <li><a href = "#">Instagram</li>

         </ul>
       </li>
       <li><a href = "#">Portfolio</li>
       <li><a href = "#">Contact</li>
     </ul>

   </div>

  </body>



</html>

我会接受你能给我的任何帮助,因为我很新。

1 个答案:

答案 0 :(得分:1)

首先,您已将所有a tags取消关闭。

您只需添加这些cdns即可使代码正常运行。这些bootstrap 3 cdn&#39; s -

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

工作代码段

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/f42d4534b0.js"></script>
<html>

<head>
  <title>

  </title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>

  <div class="navbar navbar-custom navbar-fixed-top">

    <div class="container">

      <a href="#" class="navbar-brand">evdanger</a>

      <button class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navHeaderCollapse">
     <i class = "fa fa-bars"></i> 
   </button>

      <div class="collapse navbar-collapse navHeaderCollapse">

        <ul class="nav navbar-nav navbar-right">

          <li class="active"><a href="#">Home</a></li>
          <li class="dropdown">

            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Social Media</a>

            <ul class="dropdown-menu">

              <li><a href="#">Twitter</a></li>
              <li><a href="#">Facebook</a></li>
              <li><a href="#">Google+</a></li>
              <li><a href="#">Instagram</a></li>

            </ul>
          </li>
          <li><a href="#">Portfolio</a></li>
          <li><a href="#">Contact</a></li>
        </ul>

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

</html>
&#13;
&#13;
&#13;

如果你想使用bootstrap 4这些是bootstrap 4 cdn&#39; s -

<link rel="stylesheet" 
 href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0- alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> 

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

   <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> 

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

来自官方网站的bootstrap 4导航栏的简单示例

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="#">Navbar</a>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
&#13;
&#13;
&#13;