How to add hamburger menu in bootstrap

試著忘記壹切 提交于 2019-11-26 12:23:44

问题


I need some help with bootstrap nav. I want it to be toggled via a hamburger icon on mobile.

Here it is on codepen: http://codepen.io/sadman/pen/hfGwv (link invalid)

.navbar,
.navbar-inverse {
  border-radius: 0;
  border: none;
  margin-bottom: 0;
  min-height: 80px;
}

.nav li {
  display: inline;
  color: white;
}

.navbar-inverse .navbar-nav>li>a {
  color: #ffffff;
  font-family: Lato;
  font-size: 1.7em;
  font-weight: 300;
  padding: 30px 25px 33px 25px;
}

.navbar-inverse .navbar-nav li a:hover {
  background-color: #444444;
  transition: 0.7s all linear;
  height: 100%;
}
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js\"></script>
<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css\">

<nav class=\"navbar navbar-inverse navbar-static-top\" role=\"navigation\">
  <div class=\"container\">
    <ul class=\"nav navbar-nav\">
      <li><a href=\"index.php\">Home</a></li>
      <li><a href=\"about.php\">About</a></li>
      <li><a href=\"#portfolio\">Portfolio</a></li>
      <li><a href=\"#\">Blog</a></li>
      <li><a href=\"contact.php\">Contact</a></li>
    </ul>
  </div>
</nav>

回答1:


All you have to do is read the code on getbootstrap.com:

Codepen

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="index.php">Home</a></li>
        <li><a href="about.php">About</a></li>
        <li><a href="#portfolio">Portfolio</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="contact.php">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>



回答2:


To create icon you can use Glyphicon in Bootstrap:

<a href="#" class="btn btn-info btn-sm">
    <span class="glyphicon glyphicon-menu-hamburger"></span>
</a>

And then control size of icon in css:

.glyphicon-menu-hamburger {
  font-size: npx;
}


来源:https://stackoverflow.com/questions/26317679/how-to-add-hamburger-menu-in-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!