Skip to content

Commit a493807

Browse files
committed
compact navbar on mobile
1 parent 5b39cde commit a493807

2 files changed

Lines changed: 132 additions & 14 deletions

File tree

_layouts/default.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<header class="site-header">
2929
<div class="container site-header__inner">
3030
<a class="site-title" href="{{ '/' | relative_url }}">{{ site.title }}</a>
31+
<input class="site-nav-toggle" id="site-nav-toggle" type="checkbox" aria-label="Toggle main navigation">
32+
<label class="nav-toggle" for="site-nav-toggle">
33+
<span class="nav-toggle__icon" aria-hidden="true"></span>
34+
<span class="visually-hidden">Menu</span>
35+
</label>
3136
<nav class="site-nav" aria-label="Main navigation">
3237
{% for x in site.data.nav %}
3338
<a class="nav-link" href="{{ x.link | relative_url }}">{{ x.name }}</a>

_sass/_style.scss

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@ img {
102102
text-decoration: none;
103103
}
104104

105+
.site-nav-toggle,
106+
.nav-toggle {
107+
display: none;
108+
}
109+
105110
.site-nav {
106111
display: flex;
107112
align-items: center;
108113
justify-content: flex-end;
109114
gap: 24px;
110115
flex-wrap: wrap;
116+
margin-left: auto;
111117
}
112118

113119
.nav-link {
@@ -645,16 +651,6 @@ img {
645651
font-size: 17px;
646652
}
647653

648-
.site-header__inner {
649-
align-items: flex-start;
650-
flex-direction: column;
651-
}
652-
653-
.site-nav {
654-
justify-content: flex-start;
655-
width: 100%;
656-
}
657-
658654
.page-hero h1 {
659655
font-size: 42px;
660656
}
@@ -700,6 +696,117 @@ img {
700696
}
701697
}
702698

699+
@media (max-width: 760px) {
700+
.site-header__inner {
701+
position: relative;
702+
min-height: 68px;
703+
padding-right: 100px;
704+
gap: 16px;
705+
}
706+
707+
.site-title {
708+
max-width: calc(100% - 100px);
709+
font-size: 16px;
710+
}
711+
712+
.nav-toggle {
713+
position: absolute;
714+
top: 50%;
715+
right: 40px;
716+
display: inline-flex;
717+
align-items: center;
718+
justify-content: center;
719+
width: 44px;
720+
min-height: 40px;
721+
padding: 0;
722+
transform: translateY(-50%);
723+
border: 1px solid var(--rule);
724+
border-radius: 6px;
725+
background: var(--paper);
726+
color: var(--ink);
727+
cursor: pointer;
728+
font-size: 14px;
729+
font-weight: 750;
730+
line-height: 1;
731+
list-style: none;
732+
}
733+
734+
.site-nav-toggle {
735+
position: absolute;
736+
display: block;
737+
width: 1px;
738+
height: 1px;
739+
padding: 0;
740+
margin: -1px;
741+
overflow: hidden;
742+
clip: rect(0, 0, 0, 0);
743+
white-space: nowrap;
744+
border: 0;
745+
}
746+
747+
.nav-toggle:hover,
748+
.site-nav-toggle:checked + .nav-toggle {
749+
border-color: var(--teal);
750+
color: var(--teal);
751+
}
752+
753+
.site-nav-toggle:focus-visible + .nav-toggle {
754+
outline: 2px solid var(--accent);
755+
outline-offset: 3px;
756+
}
757+
758+
.nav-toggle__icon {
759+
position: relative;
760+
width: 16px;
761+
height: 12px;
762+
display: inline-block;
763+
border-top: 2px solid currentColor;
764+
border-bottom: 2px solid currentColor;
765+
}
766+
767+
.nav-toggle__icon::before {
768+
content: "";
769+
position: absolute;
770+
top: 50%;
771+
left: 0;
772+
right: 0;
773+
border-top: 2px solid currentColor;
774+
transform: translateY(-50%);
775+
}
776+
777+
.site-nav-toggle:not(:checked) ~ .site-nav {
778+
display: none;
779+
}
780+
781+
.site-nav-toggle:checked ~ .site-nav {
782+
position: absolute;
783+
top: calc(100% + 10px);
784+
right: 40px;
785+
z-index: 20;
786+
width: min(220px, calc(100vw - 32px));
787+
display: grid;
788+
align-items: stretch;
789+
justify-content: stretch;
790+
gap: 0;
791+
padding: 8px;
792+
border: 1px solid var(--rule);
793+
border-radius: 6px;
794+
background: var(--paper);
795+
box-shadow: 0 16px 32px rgba(24, 32, 32, 0.12);
796+
}
797+
798+
.site-nav-toggle:checked ~ .site-nav .nav-link {
799+
display: block;
800+
padding: 12px;
801+
border-radius: 4px;
802+
line-height: 1.2;
803+
}
804+
805+
.site-nav-toggle:checked ~ .site-nav .nav-link:hover {
806+
background: var(--soft);
807+
}
808+
}
809+
703810
@media (max-width: 580px) {
704811
.container {
705812
width: calc(100% - 32px);
@@ -710,12 +817,18 @@ img {
710817

711818
.site-header__inner {
712819
min-height: auto;
713-
padding: 18px 0;
714-
gap: 18px;
820+
padding-right: 60px;
821+
padding-top: 18px;
822+
padding-bottom: 18px;
823+
}
824+
825+
.site-title {
826+
max-width: calc(100% - 60px);
715827
}
716828

717-
.site-nav {
718-
gap: 18px 22px;
829+
.nav-toggle,
830+
.site-nav-toggle:checked ~ .site-nav {
831+
right: 0;
719832
}
720833

721834
.home-hero {

0 commit comments

Comments
 (0)