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: ...@@ -46,10 +46,8 @@ See also:
The associated CSS will then display the navigation elements as a The associated CSS will then display the navigation elements as a
menu. menu.
{% endcomment %} {% endcomment %}
<button <input type="checkbox" id="mobile_toggle" class="d-none">
class="js-mobile_nav-toggle nav_toggle" <label for="mobile_toggle" class="nav_toggle"></label>
onclick="this.classList.toggle('active')">
</button>
<nav> <nav>
{% for entry in site.data.navigation.header %} {% for entry in site.data.navigation.header %}
......
...@@ -216,43 +216,49 @@ ...@@ -216,43 +216,49 @@
} }
} }
.nav_toggle.active { /*
&:before { This SCSS part is used to mimic the behavior, previously implemented
content: "\f00d"; via Javascript, in pure CSS using a technique called "Checkbox Hack"
color: $color-helmholtz-green; 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
& + nav { for applying different style.
*/
display: flex; #mobile_toggle:checked ~ .nav_toggle::before {
flex-direction: column; content: "\f00d";
justify-content: flex-end; color: $color-helmholtz-green;
align-content: center; }
position: absolute;
left: $document-side-margin;
right: $document-side-margin;
top: 0;
font-size: 1rem; #mobile_toggle:checked ~ nav {
color: white;
background-color: $color-helmholtz-green; display: flex;
margin-left: auto; flex-direction: column;
margin-right: auto; justify-content: flex-end;
padding-top: 1.5rem; /* Determined by eyeballing */ align-content: center;
padding-left: 0.5rem;
padding-right: 0.5rem; position: absolute;
padding-bottom: 0.5rem; left: $document-side-margin;
border-radius: 0.5em; right: $document-side-margin;
z-index: -1; /* Go below the header */ top: 0;
@include respond-to-medium( font-size: 1rem;
margin-top, $header-min-height color: white;
); background-color: $color-helmholtz-green;
margin-left: auto;
a { margin-right: auto;
width: auto; /* Allow parent flexbox to determine */ 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