Hamburger Navigation
HTML
<nav id="demo-hamburger-nav">
<div class="hamburger-container">Hamburger Navigation
<div class="demo-hamburger-menu">
<div class="demo-hamburger-icon" onclick="toggleMenu()">
<span></span>
<span></span>
<span></span>
</div>
<div class="demo-menu-links">
<li><a href="#about" onclick="toggleMenu()">About</a></li>
<li><a href="#experience" onclick="toggleMenu()">Experience</a></li>
<li><a href="#projects" onclick="toggleMenu()">Projects</a></li>
<li><a href="#contact" onclick="toggleMenu()">Contact</a></li>
</div>
</div>
</div>
</nav>
CSS
/* ========== HAMBURGER NAVIGATION ========== */
#demo-hamburger-nav {
display: flex;
justify-content: space-between;
align-items: center;
height: 80px;
background-color: black;
border-bottom: 1px solid #e5e5e5;
position: relative; /* changed from fixed */
width: 100%;
z-index: 999;
padding: 0 5%;
}
/* ========== HAMBURGER MENU DROPDOWN INSIDE CONTAINER ========== */
/* HAMBURGER MENU */
.demo-hamburger-menu {
position: relative;
display: inline-block;
}
.demo-hamburger-icon {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 24px;
width: 30px;
cursor: pointer;
}
.demo-hamburger-icon span {
width: 100%;
height: 2px;
background-color: white;
transition: all 0.3s ease-in-out;
}
.demo-menu-links {
position: absolute;
top: 100%;
right: 0;
background-color: lightgray;
width: 200px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
max-height: 0;
display: flex;
flex-direction: column;
align-items: center;
transition: max-height 0.3s ease-in-out, padding 0.3s ease-in-out;
padding: 0;
}
.demo-menu-links.open {
max-height: 300px;
padding: 1rem;
}
.demo-menu-links li {
list-style: none;
}
.demo-menu-links a {
display: block;
padding: 10px;
text-align: center;
font-size: 1.5rem;
color: black;
text-decoration: none;
transition: all 0.3s ease-in-out;
}
.demo-menu-links.open {
max-height: 300px;
}
.demo-hamburger-icon.open span:first-child {
transform: rotate(45deg) translate(10px, 5px);
}
.demo-hamburger-icon.open span:nth-child(2) {
opacity: 0;
}
.demo-hamburger-icon.open span:last-child {
transform: rotate(-45deg) translate(10px, -5px);
}
.demo-hamburger-icon span:first-child {
transform: none;
opacity: 1;
}
JS
function toggleMenu() {
const menu = document.querySelector('.demo-menu-links');
const icon = document.querySelector('.demo-hamburger-icon');
menu.classList.toggle('open');
icon.classList.toggle('open');
};