CSS Grid, CSS Subgrid, Event Listeners, Transitions, Responsive Layout

Solution retrospective
I learned how to build a responsive hidden burger menu using HTML, CSS, and JavaScript. This involved using hidden elements, CSS positioning, CSS transitions for smooth animations, and JavaScript event listeners to toggle the menu's visibility by adjusting the menu's position on the workflow.
<img id="menu__icon" src="/assets/images/icon-menu.svg" alt="icon-menu" />
#menu {
height: 100vh;
width: 75vw;
background: hsl(36, 100%, 99%);
position: fixed;
top: 0;
transition: 0.5s ease-in-out;
z-index: 2;
}
.hidden {
right: -100%;
}
.visible {
right: 0;
}
let menuIcon = document.getElementById("menu__icon");
menuIcon.addEventListener("click", () => {
menu.classList.remove("hidden");
menu.classList.add("visible");
});
iconMenuClose.addEventListener("click", () => {
menu.classList.remove("visible");
menu.classList.add("hidden");
});
Continued development
In future projects, I want to focus on responsively generated components. While I have learned how to create a burger menu, I want to refine my skills in dynamically generating and modifying UI elements based on screen size and user interactions.
Some key areas I plan to improve:
- Dynamic Component Rendering: Creating elements in JavaScript based on user actions or device breakpoints.
- CSS Flexibility: Enhancing my understanding of clamp(), min(), max(), and other modern CSS techniques for better responsiveness.
- Performance Optimization: Ensuring that dynamically generated components do not negatively impact page load speed and user experience.
1. Toggling the Menu Visibility
- Challenge: The menu needed to be hidden by default and only appear when the button was clicked.
- Solution: I used
display: none
in CSS and toggled a class using JavaScript to show the menu.
.menu {
display: none;
}
.menu.open {
display: block;
}
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Ayman Soliman's solution.
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord