hamburger menu code example

Example 1: bootstrap hamburger menu

<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>

Example 2: how to make a nav burger with html css and javascript

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, intial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<meta http-equiv="Content-Type" content="text/html" />
		<title>burger example</title>
		<style type="text/css">
        .burger {
        	display: inline-block;
        	cursor: pointer;
        	transform: translate(0, 5px);
        }
          
        .bar1, .bar2, .bar3 {
        	width: 35px;
        	height: 5px;
        	background: #000;
        	margin: 6px 0;
        	-webkit-border-radius: 25%;
        	-moz-border-radius: 25%;
        	border-radius: 25%;
        	transition: all 0.75s cubic-bezier(0.5, -1, 0.59, 1.88);
        }
          
        .opened-nav .bar1 {
        	-webkit-transform: rotate(-45deg) translate(-9px, 6px);
        	transform: rotate(-45deg) translate(-9px, 6px);
        }
          
        .opened-nav .bar2 {
        	opacity: 0;
        	transform: translate(-17.5px, 0);
        }
          
        .opened-nav .bar3 {
        	-webkit-transform: rotate(45deg) translate(-8px, -8px);
        	transform: rotate(45deg) translate(-8px, -8px);
        }
		</style>
	</head>
	<body>
		<div class="burger" onclick="toggle_burger(this)">
			<div class="bar1"></div>
			<div class="bar2"></div>
			<div class="bar3"></div>
		</div>
      	<script type="text/javascript">
			function toggle_burger(x) {
				x.classList.toggle("opened-nav");
			}
		</script>
	</body>
</html>

Example 3: hamburger menu

hamburger menu

Tags:

Misc Example