responsive hamburger menu code example
Example 1: burger menu css
<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: css responsive navigation
#header{
position:fixed;
z-index:1000;
left:0;
top:0;
width:100vw;
height:auto;
}
#header .header{
min-height:8vh;
background-color: rgba(0,0,0,0.3);
}
#header .nav-bar{
display:flex;
align-items:center;
justify-content:space-between;
width:100%;
height:100%;
max-width:1300px;
padding:0 10px;
}
#header .nav-list ul{
list-style:none;
position:absolute;
background-color:rgb(31,30,30);
width:100vw;
height:100vh;
left:0;
top:0;
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
z-index:1;
overflow-x:hidden;
}
#header .nav-list ul a{
font-size:2.5rem;
font-weight:500;
letter-spacing: .2rem;
text-decoration:none;
color:white;
text-transform:uppercase;
padding:20px;
display:block;
}