折叠的Bootstrap Navbar不显示

时间:2016-07-26 04:38:06

标签: html css twitter-bootstrap

因此,当折叠时,我的导航栏菜单按钮有效,但在快速加载动画后,菜单消失了。不确定为什么会这样,我已经搜索了其他问题和引导文档,无法弄明白。该网站为http://philipeckert.com

HTML:

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"> 
        <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="#brand">Eckert</a>
    </div>
    <div class="collapse navbar-collapse" id="navbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#gohereforabout">About</a></li>
        <li><a href="#Portfolio">Portfolio</a></li>
        <li><a href="#Contact">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

CSS:

.navbar-default {
  background-color: rgb(0, 32, 128);
  border-color: #000000;
}

.navbar-default .navbar-brand {
  color: white;
}

.navbar-default .navbar-toggle .icon-bar {
  background-color: white;
}

.nav.navbar-nav.navbar-right li a {
  color: white;
  font-family: 'Ubuntu', sans-serif;
}

@media (max-width: 990px) {
    .navbar-header {
        float: none;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-nav {
        float: none!important;
        margin: 7.5px -15px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

3 个答案:

答案 0 :(得分:0)

只需从@media查询中删除.navbar-collapse.collapse css:

/*Remove this */
.navbar-collapse.collapse {
        display: none!important;
}

这是小提琴演示:https://jsfiddle.net/2pua65co/

答案 1 :(得分:0)

删除此css你的style.css第30行

.navbar-collapse.collapse {
    display: none !important;
}

答案 2 :(得分:0)

您需要将此CSS规则添加到功能属性:

.navbar.navbar-default .collapse.in {
    display: block !important;
}

有关详细信息,请参阅Collapse Usage

工作示例:

.navbar.navbar-default {
  background-color: rgb(0, 32, 128);
  border-color: #000000;
}
.navbar.navbar-default .navbar-brand {
  color: white;
}
.navbar.navbar-default .navbar-toggle .icon-bar {
  background-color: white;
}
.navbar.navbar-default .navbar-nav.navbar-right li a {
  color: white;
  font-family: 'Ubuntu', sans-serif;
}
@media (max-width: 990px) {
  .navbar.navbar-default .navbar-header {
    float: none;
  }
  .navbar.navbar-default .navbar-left,
  .navbar.navbar-default .navbar-right {
    float: none !important;
  }
  .navbar.navbar-default .navbar-toggle {
    display: block;
  }
  .navbar.navbar-default .navbar-collapse {
    border-top: 1px solid transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  .navbar.navbar-default.navbar-fixed-top {
    top: 0;
    border-width: 0 0 1px;
  }
  .navbar.navbar-default .navbar-collapse {
    overflow: hidden;
  }
  .navbar.navbar-default .navbar-collapse.collapse {
    display: none!important;
  }
  .navbar.navbar-default .navbar-nav {
    float: none!important;
    margin-top: 7.5px;
  }
  .navbar.navbar-default .navbar-nav > li {
    float: none;
  }
  .navbar.navbar-default .navbar-nav > li > a {
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .navbar.navbar-default .collapse.in {
    display: block !important;
  }
  .navbar.navbar-default .navbar-nav .dropdown-menu > li > a,
  .navbar.navbar-default .navbar-nav .dropdown-menu > li > a:hover,
  .navbar.navbar-default .navbar-nav .dropdown-menu > li > a:focus {
    color: #777;
  }
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<nav class="navbar navbar-default navbar-fixed-top navbar">
  <div class="container-fluid">

    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <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="#brand">Eckert</a>
    </div>

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

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