Header: make mobile responsive

This commit is contained in:
Akemi Izuko 2024-01-01 16:03:04 -07:00
parent b9083aa263
commit e5e5610dfa
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -4,7 +4,7 @@ import { SITE_TITLE } from '../consts';
--- ---
<header style="width: 100%" class="font-sans sticky top-0 md:static bg-white underline-offset-4 z-40"> <header style="width: 100%" class="font-sans sticky top-0 md:static bg-white underline-offset-4 z-40">
<nav> <nav class="wide-screen">
<div class="flex items-center space-x-8"> <div class="flex items-center space-x-8">
<HeaderLink href="/"><img style="padding: 2px;" src="/favicon.avif" /></HeaderLink> <HeaderLink href="/"><img style="padding: 2px;" src="/favicon.avif" /></HeaderLink>
<HeaderLink href="/blog">Blog</HeaderLink> <HeaderLink href="/blog">Blog</HeaderLink>
@ -12,9 +12,7 @@ import { SITE_TITLE } from '../consts';
<HeaderLink href="/llama">Llama</HeaderLink> <HeaderLink href="/llama">Llama</HeaderLink>
<HeaderLink href="/meow">Meow</HeaderLink> <HeaderLink href="/meow">Meow</HeaderLink>
</div> </div>
<div class="fun-quote" style="margin: 0"> <div class="fun-quote text-2xl">ReLUwU activated</div>
<span style="font-family: var(--font-title);" class="text-2xl">ReLUwU activated</span>
</div>
<div class="social-links flex space-x-8 items-center"> <div class="social-links flex space-x-8 items-center">
<HeaderLink href="https://github.com/aizuko">GitHub</HeaderLink> <HeaderLink href="https://github.com/aizuko">GitHub</HeaderLink>
<HeaderLink href="/contact">Contact</HeaderLink> <HeaderLink href="/contact">Contact</HeaderLink>
@ -26,10 +24,31 @@ import { SITE_TITLE } from '../consts';
</HeaderLink> </HeaderLink>
</div> </div>
</nav> </nav>
<nav class="narrow-screen">
<div class="fun-quote">
<a href="/">ReLUwU activated</a>
</div>
<input id="menu-toggle" type="checkbox">
<label class="menu-button-container" for="menu-toggle">
<div class="menu-button"></div>
</label>
<ul class="menu">
<li><HeaderLink href="/">Home</HeaderLink></li>
<li><HeaderLink href="/blog">Blog</HeaderLink></li>
<li><HeaderLink href="/unix">Unix</HeaderLink></li>
<li><HeaderLink href="/llama">Llama</HeaderLink></li>
<li><HeaderLink href="/meow">Meow</HeaderLink></li>
<li><HeaderLink href="/contact">Contact</HeaderLink></li>
<li><HeaderLink href="/akemi_resume.pdf">Resume</HeaderLink></li>
</ul>
</nav>
</header> </header>
<style> <style>
header nav { /*****************************************
* Full-width navigation bar.
****************************************/
header nav.wide-screen {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
@ -39,18 +58,155 @@ import { SITE_TITLE } from '../consts';
justify-items: center; justify-items: center;
align-items: center; align-items: center;
} }
header nav div { header nav.wide-screen div {
display: flex; display: flex;
flex: 1; flex: 1;
justify-content: center; justify-content: center;
} }
header nav div:first-child { header nav.wide-screen div:first-child {
justify-content: flex-start; justify-content: flex-start;
} }
header nav div:last-child { header nav.wide-screen div:last-child {
justify-content: flex-end; justify-content: flex-end;
} }
header nav img { header nav.wide-screen img {
height: 48px; height: 48px;
} }
header nav.wide-screen .fun-quote {
margin: 0;
font-family: var(--font-title);
}
/*****************************************
* Sandwich-style navigation bar.
****************************************/
header nav.narrow-screen {
background-color: black;
color: white;
font-family: var(--font-sans);
font-weight: 600;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 14px 24px;
font-size: 1.125rem;
user-select: none;
justify-items: center;
align-items: center;
}
header nav.narrow-screen .fun-quote {
font-family: var(--font-title);
margin: 0;
}
/*****************************************
* Sandwich menu code adapted from:
* https://codepen.io/alvarotrigo/pen/MWEJEWG
****************************************/
/* Toggle menu allows for clicking, but isn't diplayed */
header nav.narrow-screen #menu-toggle {
display: none;
}
header nav.narrow-screen #menu-toggle:checked
+ .menu-button-container .menu-button::before {
margin-top: 0px;
transform: rotate(45deg);
}
header nav.narrow-screen #menu-toggle:checked
+ .menu-button-container .menu-button {
background: rgba(255, 255, 255, 0);
}
header nav.narrow-screen #menu-toggle:checked
+ .menu-button-container .menu-button::after {
margin-top: 0px;
transform: rotate(-45deg);
}
/* Actual sandwich menu visual - consists of 3 horizontal boxes */
header nav.narrow-screen .menu-button-container {
display: flex;
height: 100%;
width: 30px;
cursor: pointer;
flex-direction: column;
justify-content: center;
align-items: center;
}
header nav.narrow-screen .menu-button,
header nav.narrow-screen .menu-button::before,
header nav.narrow-screen .menu-button::after {
display: block;
background-color: #fff;
position: absolute;
height: 4px;
width: 30px;
transition: transform 400ms cubic-bezier(0.23, 1, 0.32, 1);
border-radius: 2px;
}
header nav.narrow-screen .menu-button::before {
content: '';
margin-top: -8px;
}
header nav.narrow-screen .menu-button::after {
content: '';
margin-top: 8px;
}
/* The dropdown menu after clicking the visual */
header nav.narrow-screen .menu {
position: absolute;
top: 0;
margin-top: 50px;
left: 0;
flex-direction: column;
width: 100%;
justify-content: center;
align-items: center;
}
header nav.narrow-screen #menu-toggle ~ .menu li {
height: 0;
margin: 0;
padding: 0;
border: 0;
transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1);
}
header nav.narrow-screen #menu-toggle:checked ~ .menu li {
border: 1px solid black;
height: 2.5em;
padding: 0.5em;
transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1);
}
header nav.narrow-screen .menu > li {
display: flex;
justify-content: center;
margin: 0;
padding: 0.5em 0;
width: 100%;
color: white;
background-color: black;
}
header nav.narrow-screen .menu > li:not(:last-child) {
border-bottom: 1px solid black;
}
/*****************************************
* >>>> Header breakpoints <<<<
* 1100px: remove center quote
* 760px: collapse into sandwich
*
* Note: {min,max}-width is inclusive
****************************************/
@media (max-width: 1100px) {
header nav.wide-screen .fun-quote {
display: none;
}
}
@media (min-width: 761px) {
header nav.narrow-screen {
display: none;
}
}
@media (max-width: 760px) {
header nav.wide-screen {
display: none;
}
}
</style> </style>