Skip to content

Commit 3d97eef

Browse files
Fix responsive header navigation with mobile hamburger menu
1 parent 09e0a9c commit 3d97eef

2 files changed

Lines changed: 103 additions & 2 deletions

File tree

website/index.html

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,29 @@
5757
<header class="site-header">
5858
<div class="container nav">
5959
<a class="brand" href="#top" aria-label="PromptOpsKit home">PromptOpsKit</a>
60-
<nav aria-label="Primary">
60+
61+
<button
62+
class="menu-toggle"
63+
type="button"
64+
aria-expanded="false"
65+
aria-controls="primary-nav"
66+
aria-label="Toggle navigation menu"
67+
>
68+
<span aria-hidden="true"></span>
69+
<span>Menu</span>
70+
</button>
71+
72+
<nav id="primary-nav" aria-label="Primary">
6173
<a href="#why">Why</a>
6274
<a href="#what">What</a>
6375
<a href="#quickstart">How</a>
6476
<a href="#features">Features</a>
6577
<a href="#faq">FAQ</a>
6678
<a href="/docs/index.html">Docs</a>
79+
<a class="button button-primary mobile-github" href="https://github.com/PredictabilityAtScale/promptopskit">GitHub</a>
6780
</nav>
68-
<a class="button button-primary" href="https://github.com/PredictabilityAtScale/promptopskit">GitHub</a>
81+
82+
<a class="button button-primary desktop-github" href="https://github.com/PredictabilityAtScale/promptopskit">GitHub</a>
6983
</div>
7084
</header>
7185

@@ -349,5 +363,38 @@ <h2>Repo-native, not dashboard-native</h2>
349363
<p><a href="https://github.com/PredictabilityAtScale/promptopskit">GitHub</a></p>
350364
</div>
351365
</footer>
366+
<script>
367+
(() => {
368+
const header = document.querySelector('.site-header');
369+
const toggle = document.querySelector('.menu-toggle');
370+
const nav = document.getElementById('primary-nav');
371+
372+
if (!header || !toggle || !nav) return;
373+
374+
const closeMenu = () => {
375+
header.classList.remove('is-menu-open');
376+
toggle.setAttribute('aria-expanded', 'false');
377+
};
378+
379+
toggle.addEventListener('click', () => {
380+
const isOpen = header.classList.toggle('is-menu-open');
381+
toggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
382+
});
383+
384+
nav.querySelectorAll('a').forEach((link) => {
385+
link.addEventListener('click', () => {
386+
if (window.matchMedia('(max-width: 900px)').matches) {
387+
closeMenu();
388+
}
389+
});
390+
});
391+
392+
window.addEventListener('resize', () => {
393+
if (!window.matchMedia('(max-width: 900px)').matches) {
394+
closeMenu();
395+
}
396+
});
397+
})();
398+
</script>
352399
</body>
353400
</html>

website/styles.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ body {
3535
}
3636

3737
.nav {
38+
position: relative;
3839
display: flex;
3940
align-items: center;
4041
justify-content: space-between;
@@ -48,6 +49,28 @@ body {
4849
text-decoration: none;
4950
}
5051

52+
.menu-toggle {
53+
display: none;
54+
align-items: center;
55+
gap: 0.45rem;
56+
border: 1px solid var(--line);
57+
border-radius: 6px;
58+
background: #fff;
59+
color: var(--text);
60+
font-weight: 600;
61+
padding: 0.5rem 0.7rem;
62+
cursor: pointer;
63+
}
64+
65+
.menu-toggle span[aria-hidden='true'] {
66+
font-size: 1rem;
67+
line-height: 1;
68+
}
69+
70+
.mobile-github {
71+
display: none;
72+
}
73+
5174
nav {
5275
display: flex;
5376
gap: 1.25rem;
@@ -232,8 +255,39 @@ ul {
232255
}
233256

234257
@media (max-width: 900px) {
258+
.menu-toggle {
259+
display: inline-flex;
260+
margin-left: auto;
261+
}
262+
263+
.desktop-github {
264+
display: none;
265+
}
266+
235267
nav {
236268
display: none;
269+
position: absolute;
270+
top: calc(100% - 6px);
271+
right: 0;
272+
left: 0;
273+
z-index: 12;
274+
border: 1px solid var(--line);
275+
border-radius: 8px;
276+
background: #fff;
277+
padding: 0.75rem;
278+
box-shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
279+
flex-direction: column;
280+
align-items: flex-start;
281+
gap: 0.75rem;
282+
}
283+
284+
.site-header.is-menu-open nav {
285+
display: flex;
286+
}
287+
288+
.mobile-github {
289+
display: inline-block;
290+
margin-top: 0.25rem;
237291
}
238292

239293
.grid.two,

0 commit comments

Comments
 (0)