bootstrap navbar响应不起作用

时间:2016-07-15 06:28:09

标签: javascript jquery html css

在全窗口屏幕上,我完全按照自己的意愿使用导航栏。但是,一旦我将窗口缩小以检查它是否具有反应性,我就不会一个接一个地获取所有菜单按钮(主页,技能,关于,联系)其次,当我将窗口屏幕调整为全屏时,导航栏会变小。

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags always come first -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">

    <style type="text/css">
      
      #navbar .nav-pills .nav-item.open .nav-link,
      #navbar .nav-pills .nav-item.open .nav-link:focus,
      #navbar .nav-pills .nav-item.open .nav-link:hover,
      #navbar .nav-pills .nav-link.active,
      #navbar .nav-pills .nav-link.active:focus,
      #navbar .nav-pills .nav-link.active:hover 
      {
        background-color: #e7e7e7;
        border-color: transparent;
        color: #555555;
      }

      .navbar-default 
      {
        background-color: #610B0B ;
        border-radius:0px;
      
      }

      .navbar.center .navbar-inner 
      {
        text-align: center;
      }

      .navbar.center .navbar-inner .nav 
      {
        float: none;
        display:inline-block;
      }

      .navbar-default .navbar-nav > li > a 
      {
        color: white;
        font-size: 15px;
        font-family: 'Droid Serif', Georgia, Times, serif;
        letter-spacing: 1px;
        margin: 3px 10px -3px 10px;
        border: 2px solid transparent;
        padding: 8px;

      }

      .navbar-default .navbar-nav > li > a:hover,
      .navbar-default .navbar-nav > li > a:focus
      { 
        border: 2px solid white;
        border-radius: 5px;
        color: white;
        padding: 8px;
      }

      .navbar-default .navbar-nav > .active > a, 
      .navbar-default .navbar-nav > .active > a:hover, 
      .navbar-default .navbar-nav > .active > a:focus 
      {
        border: 2px solid white;
        border-radius: 5px;
        color: #555;
        background-color: #E7E7E7;
      }

      .navbar-default .navbar-nav > .open > a, 
      .navbar-default .navbar-nav > .open > a:hover, 
      .navbar-default .navbar-nav > .open > a:focus 
      {
        color: #555;
        background-color: #D5D5D5;
      }

    </style>

  </head>
<body data-spy="scroll" data-target="#navbar">

  <div id="navbar">
  
  <nav class="navbar navbar-default center navbar-fixed-top" id="navbar">

    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2">&#9776;</button>

    <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2">

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

      <div class="navbar-inner">

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

          <li class="nav-item">
            <a class="nav-link active" href="#jumbotron">HOME <span class="sr-only">(current)</span></a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#about">ABOUT</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#skills">SKILLS</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#contact">CONTACT</a>
          </li>

        </ul>

      </div>

    </div>

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

    <!-- jQuery first, then Bootstrap JS. -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
  </body>
</html>

3 个答案:

答案 0 :(得分:0)

请添加bootstrap css和js的参考。

#navbar .nav-pills .nav-item.open .nav-link,
      #navbar .nav-pills .nav-item.open .nav-link:focus,
      #navbar .nav-pills .nav-item.open .nav-link:hover,
      #navbar .nav-pills .nav-link.active,
      #navbar .nav-pills .nav-link.active:focus,
      #navbar .nav-pills .nav-link.active:hover 
      {
        background-color: #e7e7e7;
        border-color: transparent;
        color: #555555;
      }

      .navbar-default 
      {
        background-color: #610B0B ;
        border-radius:0px;
      
      }

      .navbar.center .navbar-inner 
      {
        text-align: center;
      }

      .navbar.center .navbar-inner .nav 
      {
        float: none;
        display:inline-block;
      }

      .navbar-default .navbar-nav > li > a 
      {
        color: white;
        font-size: 15px;
        font-family: 'Droid Serif', Georgia, Times, serif;
        letter-spacing: 1px;
        margin: 3px 10px -3px 10px;
        border: 2px solid transparent;
        padding: 8px;

      }

      .navbar-default .navbar-nav > li > a:hover,
      .navbar-default .navbar-nav > li > a:focus
      { 
        border: 2px solid white;
        border-radius: 5px;
        color: white;
        padding: 8px;
      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<body data-spy="scroll" data-target="#navbar">

  <div id="navbar">
  
  <nav class="navbar navbar-default center navbar-fixed-top" id="navbar">

    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2">&#9776;</button>

    <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2">

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

      <div class="navbar-inner">

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

          <li class="nav-item">
            <a class="nav-link active" href="#jumbotron">HOME <span class="sr-only">(current)</span></a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#about">ABOUT</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#skills">SKILLS</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#contact">CONTACT</a>
          </li>

        </ul>

      </div>

    </div>

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

答案 1 :(得分:0)

您需要进行正确的导入,请参阅以下代码。

#navbar .nav-pills .nav-item.open .nav-link,
      #navbar .nav-pills .nav-item.open .nav-link:focus,
      #navbar .nav-pills .nav-item.open .nav-link:hover,
      #navbar .nav-pills .nav-link.active,
      #navbar .nav-pills .nav-link.active:focus,
      #navbar .nav-pills .nav-link.active:hover 
      {
        background-color: #e7e7e7;
        border-color: transparent;
        color: #555555;
      }

      .navbar-default 
      {
        background-color: #610B0B!important ;
        border-radius:0px;
      
      }

      .navbar.center .navbar-inner 
      {
        text-align: center;
      }

      .navbar.center .navbar-inner .nav 
      {
        float: none;
        display:inline-block;
      }

      .navbar-default .navbar-nav > li > a 
      {
        color: white;
        font-size: 15px;
        font-family: 'Droid Serif', Georgia, Times, serif;
        letter-spacing: 1px;
        margin: 3px 10px -3px 10px;
        border: 2px solid transparent;
        padding: 8px;

      }

      .navbar-default .navbar-nav > li > a:hover,
      .navbar-default .navbar-nav > li > a:focus
      { 
        border: 2px solid white;
        border-radius: 5px;
        color: white;
        padding: 8px;
      }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="navbar">
  
  <nav class="navbar navbar-default center navbar-fixed-top" id="navbar">

    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2">&#9776;</button>

    <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2">

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

      <div class="navbar-inner">

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

          <li class="nav-item">
            <a class="nav-link active" href="#jumbotron">HOME <span class="sr-only">(current)</span></a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#about">ABOUT</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#skills">SKILLS</a>
          </li>

          <li class="nav-item">
            <a class="nav-link" href="#contact">CONTACT</a>
          </li>

        </ul>

      </div>

    </div>

  </nav>
  </div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

答案 2 :(得分:0)

从文件中删除以下css,并在其中添加一个媒体查询。它会起作用

删除此

  .navbar.center .navbar-inner .nav 
  {
    float: none;
    display:inline-block;
  }

添加此

@media (max-width:544px){
      .navbar-nav .nav-item 
      {
        float: none !important;
      }
}