If you don’t run any other JavaScript on your site but need a mobile menu, this will do the trick. Simple media queries make sure the menu button shows up on large screens only, and the navigation menu is hidden from small screens. By progressively enhancing the nav
element with a data-menu
attribute, the button toggles visibility of the menu.
HTML:
/nav.html
CSS: /styles.css
JS: /menu.js
Note that I didn’t take accessibility into account, and if JavaScript is disabled on small screens, your website visitors won’t have any way to navigate :)