diff --git a/public_html/css/hpr.css b/public_html/css/hpr.css index 0cec606..a8d4617 100644 --- a/public_html/css/hpr.css +++ b/public_html/css/hpr.css @@ -91,7 +91,7 @@ body > nav ul { margin: 0; padding: 0.25rem; } -body > nav ul li { +body > nav ul li { display: inline-block; background-color: inherit; color: inherit; @@ -513,3 +513,73 @@ fieldset > input { flex: 1; } } + +@media (max-width: 480px) { + #main_menu { + display: none; + position: absolute; + top: 100%; + left: 0; + width: 100%; + z-index: 1000; + } + + .hamburger { + display: block ! important; + } + + #main_menu.is_open { + display: block; + position: relative; + left: 0; + width: 100%; + } + + #main_menu.is_open ul { + width: fit-content; + margin: 0 auto; + } + + #main_menu.is_open ul li { + display: block; + margin-bottom: 0.5rem; + } + +} + +.hamburger { + float: right; + background-color: var(--background-secondary); + border: none; + display: none; +} + +.icon { + display: block; + mask-size: contain; + background-color: var(--link-secondary); + height: var(--font-size-default); + padding: 0.25rem; + border: solid 1px var(--link-secondary); + transition: background-color 0.2s ease; +} + +.icon:hover { + background-color: var(--link-secondary-hover); +} + +.hamburger_icon { + display: block; +} + +.hamburger_icon.is_open { + display: none ! important; +} + +.close_icon { + display: none; +} + +.close_icon.is_open { + display: block ! important; +} \ No newline at end of file diff --git a/public_html/images/icons/close-line.svg b/public_html/images/icons/close-line.svg new file mode 100644 index 0000000..4ee8e56 --- /dev/null +++ b/public_html/images/icons/close-line.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public_html/images/icons/menu-line.svg b/public_html/images/icons/menu-line.svg new file mode 100644 index 0000000..771d875 --- /dev/null +++ b/public_html/images/icons/menu-line.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public_html/js/menu.js b/public_html/js/menu.js new file mode 100644 index 0000000..ef433d7 --- /dev/null +++ b/public_html/js/menu.js @@ -0,0 +1,27 @@ +const hamburger = document.querySelector('.hamburger'); +const mainNav = document.querySelector('#main_menu'); +const hamburgerIcon = document.querySelector('.hamburger_icon'); +const closeIcon = document.querySelector('.close_icon'); + +hamburger.addEventListener('click', function() { + const isOpen = this.getAttribute('aria-expanded') === 'true'; + + this.setAttribute('aria-expanded', !isOpen); + + mainNav.classList.toggle('is_open'); + hamburgerIcon.classList.toggle('is_open'); + closeIcon.classList.toggle('is_open'); + + if (!isOpen) { + const firstLink = mainNav.querySelector('a'); + if (firstLink) firstLink.focus(); + } +}); + +document.addEventListener('keydown', function(e) { + if (e.key === 'Escape' && mainNav.classList.contains('is_open')) { + mainNav.classList.remove('is_open'); + hamburger.setAttribute('aria-expanded', 'false'); + hamburger.focus(); + } +}); \ No newline at end of file diff --git a/templates/page.tpl.html b/templates/page.tpl.html index fe19ab1..1095df4 100644 --- a/templates/page.tpl.html +++ b/templates/page.tpl.html @@ -40,6 +40,10 @@ Site Map - skip to main content + @@ -77,5 +81,6 @@