diff --git a/_includes/header.html b/_includes/header.html index 9c81660e9e98df2bed50f8af422ffad03b4243dc..3d4b665135b25e83bd73abc8bc92a6ba3c066e7a 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -46,10 +46,8 @@ See also: The associated CSS will then display the navigation elements as a menu. {% endcomment %} - <button - class="js-mobile_nav-toggle nav_toggle" - onclick="this.classList.toggle('active')"> - </button> + <input type="checkbox" id="mobile_toggle" class="d-none"> + <label for="mobile_toggle" class="nav_toggle"></label> <nav> {% for entry in site.data.navigation.header %} diff --git a/_sass/common/_header.scss b/_sass/common/_header.scss index 3f94fe56f13ac423955bb3f493cd232f74aff4b0..725d48b2ccbe63bef3174a63b6da71a87b7a049e 100644 --- a/_sass/common/_header.scss +++ b/_sass/common/_header.scss @@ -216,43 +216,49 @@ } } - .nav_toggle.active { - &:before { - content: "\f00d"; - color: $color-helmholtz-green; - } - - & + nav { - - display: flex; - flex-direction: column; - justify-content: flex-end; - align-content: center; - - position: absolute; - left: $document-side-margin; - right: $document-side-margin; - top: 0; + /* + This SCSS part is used to mimic the behavior, previously implemented + via Javascript, in pure CSS using a technique called "Checkbox Hack" + https://css-tricks.com/the-checkbox-hack/. This works by connecting + a <label> with <input type="checkbox"> and hiding the <label>. + Clicking on the label toggles the :checked state of this ID and allows + for applying different style. + */ + #mobile_toggle:checked ~ .nav_toggle::before { + content: "\f00d"; + color: $color-helmholtz-green; + } - font-size: 1rem; - color: white; - background-color: $color-helmholtz-green; - margin-left: auto; - margin-right: auto; - padding-top: 1.5rem; /* Determined by eyeballing */ - padding-left: 0.5rem; - padding-right: 0.5rem; - padding-bottom: 0.5rem; - border-radius: 0.5em; - z-index: -1; /* Go below the header */ - - @include respond-to-medium( - margin-top, $header-min-height - ); - - a { - width: auto; /* Allow parent flexbox to determine */ - } + #mobile_toggle:checked ~ nav { + + display: flex; + flex-direction: column; + justify-content: flex-end; + align-content: center; + + position: absolute; + left: $document-side-margin; + right: $document-side-margin; + top: 0; + + font-size: 1rem; + color: white; + background-color: $color-helmholtz-green; + margin-left: auto; + margin-right: auto; + padding-top: 1.5rem; /* Determined by eyeballing */ + padding-left: 0.5rem; + padding-right: 0.5rem; + padding-bottom: 0.5rem; + border-radius: 0.5em; + z-index: -1; /* Go below the header */ + + @include respond-to-medium( + margin-top, $header-min-height + ); + + a { + width: auto; /* Allow parent flexbox to determine */ } }