Skip to content

Commit bed221b

Browse files
authored
feat: uses an svg hamburger menu and pure css for mobile menu (#40)
1 parent e10b3ae commit bed221b

File tree

3 files changed

+58
-29
lines changed

3 files changed

+58
-29
lines changed

assets/css/main.css

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,41 +92,64 @@ code {
9292
@apply rounded-sm no-underline;
9393
}
9494

95-
nav input[type="checkbox"],
96-
nav label {
95+
.menu-home {
96+
@apply block md:hidden;
97+
}
98+
99+
.hamburger,
100+
.close-menu {
97101
display: none;
102+
top: 0.375rem;
103+
right: 0.375rem;
104+
border-radius: 0.25rem;
105+
background-color: var(--accent-color);
98106
}
99107

100108
@media (max-width: 576px) {
101-
nav ul {
102-
display: inline-flex;
103-
flex-direction: column;
109+
.hamburger,
110+
.close-menu {
111+
display: block; /* Show on mobile */
104112
}
105113

106-
input[type="checkbox"]:not(:checked) + ul {
114+
.mobile-menu {
107115
display: none;
116+
z-index: 40;
117+
position: fixed;
118+
top: 0;
119+
right: 0;
120+
bottom: 0;
121+
left: 0;
122+
width: 100vw;
123+
height: 100vh;
124+
overflow-y: auto;
125+
background-color: rgba(0, 0, 0, 0.9);
126+
}
127+
128+
.menu-content {
129+
display: flex;
130+
flex-direction: column;
131+
align-content: center;
132+
align-items: center;
133+
justify-content: flex-start;
134+
width: 100%;
135+
padding-top: 2rem;
108136
}
109137

110-
nav {
111-
flex-direction: row-reverse;
112-
flex-wrap: wrap;
113-
margin-right: 0;
114-
margin-left: 0;
138+
.mobile-menu:target {
139+
display: flex;
115140
}
116141

117-
nav label {
142+
.mobile-menu ul {
118143
display: flex;
119144
flex-direction: column;
120-
align-self: center;
121-
line-height: 1.6em;
122-
text-align: right;
145+
align-items: center;
146+
width: 100%;
147+
padding: 0;
123148
}
124149

125-
nav ul li {
126-
width: 100%;
127-
margin-bottom: 0;
128-
padding: 0.125rem;
129-
text-align: left;
150+
.mobile-menu ul li {
151+
margin: 1rem 0;
152+
text-align: center;
130153
}
131154
}
132155

layouts/_default/baseof.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<head>
77
{{- partial "head.html" . }}
88
</head>
9-
<body class="@container flex flex-col">
9+
<body id="body" class="@container flex flex-col w-full overflow-x-hidden relative">
1010
<header class="flex flex-row items-baseline m-0 p-0 px-2 md:pb-2 lg:mx-32 bg-neutral-100 dark:bg-neutral-900">
1111
{{- partial "header.html" . }}
1212
</header>

layouts/partials/menu.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@
99
{{- end -}}
1010
{{- end -}}
1111
{{- if $hasValidEntries -}}
12-
<nav class="flex flex-1 flex-row-reverse">
13-
<label for="menu" tabindex="0">
14-
<span class="fa-stack">
15-
<i class="fas fa-square fa-stack-2x"></i>
16-
<i class="fas fa-bars fa-stack-1x fa-inverse"></i>
17-
</span>
18-
</label>
19-
<input id="menu" type="checkbox" />
12+
<nav class="md:flex flex-1 flex-row-reverse">
13+
<a href="#mobile-menu" class="hamburger fixed z-20 rounded">
14+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
15+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
16+
</svg>
17+
</a>
18+
<div id="mobile-menu" class="mobile-menu">
19+
<div class="menu-content pt-8">
20+
<a href="#" class="close-menu fixed z-20 rounded">
21+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
22+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
23+
</svg>
24+
</a>
2025
<ul class="md:flex m-0 p-0 md:pr-4">
2126
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" $menu) -}}
2227
</ul>
28+
</div></div>
2329
</nav>
2430
{{- end -}}
2531

0 commit comments

Comments
 (0)