feat(docs): add responsive hamburger menu with animations
Implement pure CSS mobile navigation with the following features: - Collapsible sidebar nav hidden behind hamburger toggle on mobile - Animated hamburger → X icon morph using CSS transforms - Smooth slide-down transition for nav reveal (max-height/opacity) - Hamburger positioned on right side of header via absolute positioning - Uses :has() selector to detect checkbox state without JavaScript - Overflow fixes to prevent horizontal scroll on mobile devices The implementation follows suckless principles with zero JavaScript.
This commit is contained in:
100
docs/static/style.css
vendored
100
docs/static/style.css
vendored
@@ -373,10 +373,42 @@ th {
|
|||||||
background: var(--bg-sidebar);
|
background: var(--bg-sidebar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Navigation toggle (hidden by default) */
|
||||||
|
.nav-toggle {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hamburger {
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 24px;
|
||||||
|
height: 18px;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hamburger span {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 2px;
|
||||||
|
background: var(--fg);
|
||||||
|
border-radius: 1px;
|
||||||
|
transition: transform 0.3s ease, opacity 0.3s ease;
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
|
||||||
/* Responsive */
|
/* Responsive */
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
|
html {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
max-width: 100vw;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
@@ -384,9 +416,75 @@ th {
|
|||||||
height: auto;
|
height: auto;
|
||||||
border-right: none;
|
border-right: none;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .tagline {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Position hamburger on right side of header */
|
||||||
|
.sidebar header {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hamburger {
|
||||||
|
display: flex;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar nav {
|
||||||
|
flex-direction: column;
|
||||||
|
padding-top: 0;
|
||||||
|
margin-top: 0;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
max-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
opacity: 0;
|
||||||
|
transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease, padding-top 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show nav when checkbox is checked - checkbox is inside header now */
|
||||||
|
.sidebar:has(.nav-toggle:checked) nav {
|
||||||
|
max-height: 500px;
|
||||||
|
opacity: 1;
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hamburger → X morph animation */
|
||||||
|
.nav-toggle:checked~.hamburger span:nth-child(1) {
|
||||||
|
transform: translateY(8px) rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-toggle:checked~.hamburger span:nth-child(2) {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-toggle:checked~.hamburger span:nth-child(3) {
|
||||||
|
transform: translateY(-8px) rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-footer {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
padding: 2rem 1.5rem;
|
padding: 1.5rem 1rem;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
max-width: calc(100vw - 2rem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
17
docs/templates/base.html
vendored
17
docs/templates/base.html
vendored
@@ -4,12 +4,17 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
{% if page.description %}<meta name="description" content="{{ page.description }}" />{% endif %}
|
{% if page.description %}
|
||||||
|
<meta name="description" content="{{ page.description }}" />{% endif %}
|
||||||
<title>{{ title }} | {{ config.title }}</title>
|
<title>{{ title }} | {{ config.title }}</title>
|
||||||
<link rel="canonical" href="{{ base_url }}{{ page_path }}" />
|
<link rel="canonical" href="{{ base_url }}{{ page_path }}" />
|
||||||
<link rel="stylesheet" href="{{ prefix }}/style.css" />
|
<link rel="stylesheet" href="{{ prefix }}/style.css" />
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" crossorigin="anonymous" media="print" onload="this.media='all'" />
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" crossorigin="anonymous"
|
||||||
<noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" crossorigin="anonymous" /></noscript>
|
media="print" onload="this.media='all'" />
|
||||||
|
<noscript>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css"
|
||||||
|
crossorigin="anonymous" />
|
||||||
|
</noscript>
|
||||||
<link rel="icon" type="image/png" href="{{ prefix }}/logo.png" />
|
<link rel="icon" type="image/png" href="{{ prefix }}/logo.png" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -21,6 +26,12 @@
|
|||||||
sukr
|
sukr
|
||||||
</a>
|
</a>
|
||||||
<span class="tagline">suckless static sites</span>
|
<span class="tagline">suckless static sites</span>
|
||||||
|
<input type="checkbox" id="nav-toggle" class="nav-toggle" />
|
||||||
|
<label for="nav-toggle" class="hamburger" aria-label="Toggle navigation">
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
</label>
|
||||||
</header>
|
</header>
|
||||||
<nav>
|
<nav>
|
||||||
{% for item in nav %}<a href="{{ prefix }}{{ item.path }}" {% if page_path==item.path %} class="active" {% endif
|
{% for item in nav %}<a href="{{ prefix }}{{ item.path }}" {% if page_path==item.path %} class="active" {% endif
|
||||||
|
|||||||
Reference in New Issue
Block a user