Skip to content
Snippets Groups Projects
Commit ba7d6762 authored by Huste, Tobias's avatar Huste, Tobias Committed by Erxleben, Fredo
Browse files

Make hamburger menu work with CSS only

- This change makes the hamburger menu work without requiring JS and by
only using CSS techniques
- It is implemented by using a technique refered to as checkbox hack: https://css-tricks.com/the-checkbox-hack/
parent 2de49698
No related branches found
No related tags found
No related merge requests found
......@@ -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 %}
......
......@@ -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 */
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment