hamburger menu html code example
Example 1: burger menu css
/* Link to Codepen in source for PoC */
<style>
.container {
background: dodgerblue;
padding: 20px;
height: 70px;
}
#hamburger {
width: 40px;
height: 40px;
display: block;
position: relative;
float: right;
transform: rotate(0deg);
transition: .5s ease-in-out;
cursor: pointer;
}
#hamburger span {
display: block;
position: absolute;
height: 4px;
width: 100%;
background: white;
border-radius: 9px;
opacity: 1;
left: 0;
transform: rotate(0deg);
transition: .25s ease-in-out;
}
#hamburger span:nth-child(1) {
top: 0px;
}
#hamburger span:nth-child(2) {
top: 12px;
}
#hamburger span:nth-child(3) {
top: 24px;
}
#hamburger.open span:nth-child(1) {
top: 14px;
transform: rotate(135deg);
}
#hamburger.open span:nth-child(2) {
opacity: 0;
left: -60px;
}
#hamburger.open span:nth-child(3) {
top: 14px;
transform: rotate(-135deg);
}
</style>
<body>
<div class="container">
<div id="hamburger">
<span></span>
<span></span>
<span></span>
</div>
</div>
</body>
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