Skip to content

Responsive Layout & Hamburger Menu ​

The layout changes with the screen size, and on narrow screens the menu tucks into a hamburger button. Both features share the same 768px breakpoint, so they are easier to understand when looked at together.

Responsive Layout ​

responsive.css is written with max-width queries in the form @media (max-width: 768px) and @media (max-width: 1024px). This approach treats the large-screen styles as the default and overrides rules as the screen gets narrower, so it is actually a desktop-first + mobile override structure.

The README checklist says "mobile first," but it's worth knowing that the code itself is written the other way around. (If you say "mobile first" in a cover letter or a code review, it won't match the code, so I recommend either changing the approach or aligning the description.)

Hamburger Menu ​

When the .menu-toggle button is clicked, setMenuState(!state.isMenuOpen) is called to toggle the state.isMenuOpen value, and depending on that value, the is-open class is added to or removed from .nav-links. At the same time, aria-expanded and aria-label are updated to match the open/closed state.

When a link inside the menu is clicked, it is detected through event delegation (selectors.menu.addEventListener('click', ...)) and the menu closes automatically. Event delegation is covered in detail in the Event Handling article.

Summary ​

  • The responsive design is a desktop-first structure written with max-width queries
  • The hamburger menu manages the open/closed state and accessibility attributes together with a single state.isMenuOpen value

Source: Codyssey-B1/B1-1