HTML Bootstrap:仅折叠下拉菜单

时间:2017-06-20 15:59:39

标签: javascript html css twitter-bootstrap twitter-bootstrap-3

我的导航栏只有一个下拉菜单,我需要它在小屏幕上折叠成hamburguer图标。

如何将完整的导航栏,只有下拉列表折叠成hamburguer图标?

实施例: picture one is what i have, picture two is what i want to have after making windows smaller

1 个答案:

答案 0 :(得分:0)

这是一种方式

<强> Bootply

<强> CSS

@media screen and (max-width: 768px) {
  #mymenu{
    background-color: #f8f8f8;
  }
  .navbar-header{
      display: inline-block;
      z-index: 2;
      position: absolute

    }
  .navbar-right{
    z-index:1
    position:absolute;
    width:100%;
    top:0;
    left:0;
    margin-top:0;
    }
}
.navbar-toggle{display: block !important;}

<强> HTML

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Brand</a>
    </div>

      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown">
          <button type="button" id="mybtn" class="dropdown-toggle navbar-toggle collapsed" data-toggle="dropdown" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar visible-xs"></span>
          <span class="icon-bar visible-xs"></span>
          <span class="icon-bar visible-xs"></span>
            <span class="hidden-xs">Toggle</span>   
        </button>

          <ul class="dropdown-menu" id="mymenu">
            <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><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
  </div><!-- /.container-fluid -->
</nav>

具有下拉行为

<强> Bootply

<强>的CSS

@media screen and (max-width: 768px) {
  #mymenu{
    background-color: #f8f8f8;
  }
  .navbar-header{
      display: inline-block;
      z-index: 2;
      position: absolute

    }
  .navbar-right{
    z-index:1;
    position:absolute;
    top:0;
    right:15px;
    margin-top:0;
    }
}
    .navbar-toggle{display: block !important;}