单页面应用程序中的bootstrap导航栏

时间:2016-11-28 19:33:20

标签: html css twitter-bootstrap

Bootstrap的导航栏出现问题:https://jsfiddle.net/2wwgt3to/1/ 我正在制作单页应用程序,事实证明,移动的bootstraps下拉导航菜单并不能很好地处理它,即点击后它没有崩溃,我设法通过添加data-toggle="collapse" data-target="#navbar"属性来解决这个问题,然后整个菜单即使它不是下拉形式,也会崩溃。

1 个答案:

答案 0 :(得分:0)

中删除data-toggle =“collapse”data-target =“#navbar”
<div data-toggle="collapse" data-target="#navbar" id="navbar" class="navbar-collapse collapse">

编辑代码:

 <nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <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="#">Project name</a>
    </div>
    <div  id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li class="dropdown-header">Nav header</li>
            <li><a href="#">Separated link</a></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="../navbar/">Default</a></li>
        <li><a href="../navbar-static-top/">Static top</a></li>
        <li class="active"><a href="./">Fixed top <span class="sr-only">(current)</span></a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>