Skip to content

Instantly share code, notes, and snippets.

@stephankoelle
Created June 17, 2025 09:48
Show Gist options
  • Save stephankoelle/8c6194533d1a8051536bc8a1fc651fe4 to your computer and use it in GitHub Desktop.
Save stephankoelle/8c6194533d1a8051536bc8a1fc651fe4 to your computer and use it in GitHub Desktop.
Simple, good looking, css only, burger menu
<style>
/* Burger Menu Styles */
.burger-menu {
position: relative;
z-index: 1001;
}
.burger-icon {
position: fixed;
top: 20px;
left: 20px;
width: 30px;
height: 22px;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
z-index: 1001;
}
.burger-icon span {
display: block;
width: 100%;
height: 4px;
background-color: #333; /* Set a default color for the burger icon */
transition: all 0.3s ease-in-out;
}
#burger-toggle {
display: none;
}
#burger-toggle:checked + .burger-icon span:nth-child(1) {
transform: translateY(9px) rotate(45deg);
background-color: #fff; /* Set to white for contrast */
}
#burger-toggle:checked + .burger-icon span:nth-child(2) {
opacity: 0;
}
#burger-toggle:checked + .burger-icon span:nth-child(3) {
transform: translateY(-9px) rotate(-45deg);
background-color: #fff; /* Set to white for contrast */
}
.burger-nav {
position: fixed;
top: 0;
left: -100%;
width: 250px;
height: 100%;
background-color: #333;
color: white;
transition: left 0.3s ease-in-out;
z-index: 1000;
}
#burger-toggle:checked ~ .burger-nav {
left: 0;
}
.burger-nav ul {
list-style: none;
padding: 60px 20px;
margin: 0;
display: flex;
flex-direction: column;
gap: 20px;
}
.burger-nav ul li a {
color: white;
text-decoration: none;
font-size: 1.2em;
}
.burger-nav ul li a:hover {
color: #007bff;
}
}
</style>
<div class="burger-menu">
<input type="checkbox" id="burger-toggle">
<label for="burger-toggle" class="burger-icon">
<span></span>
<span></span>
<span></span>
</label>
<nav class="burger-nav">
<ul>
<li><a href="/logout">Logout</a></li>
</ul>
</nav>
</div>
<script>
// Close the menu when clicking outside
document.addEventListener('click', function(event) {
const burgerToggle = document.getElementById('burger-toggle');
const burgerMenu = document.querySelector('.burger-menu');
const isClickInside = burgerMenu.contains(event.target);
if (!isClickInside) {
burgerToggle.checked = false;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment