Skip to content

Commit 62a7c96

Browse files
authored
Move the section tabs into the header bar on wide screens (#163)
1 parent c4bdc67 commit 62a7c96

2 files changed

Lines changed: 74 additions & 38 deletions

File tree

‎src/components/Header.astro‎

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import ThemeSelect from "virtual:starlight/components/ThemeSelect";
1010
import { NAV_TABS as tabs } from "../data/nav";
1111
1212
/**
13-
* Override of Starlight's Header: the original row plus a tab row underneath
14-
* (the zensical.org pattern), so the main sections stay reachable from every
15-
* page - the splash homepage has no sidebar. The row's extra height comes
16-
* from `--sl-nav-height`, raised in custom.css; the first row keeps the
17-
* original height via `--rs-nav-row`. The tabs live in src/data/nav.ts,
18-
* shared with the Sidebar override.
13+
* Override of Starlight's Header with a section-tab nav (the zensical.org
14+
* pattern), so the main sections stay reachable from every page - the splash
15+
* homepage has no sidebar. Below 60rem the tabs sit on their own row under
16+
* the logo; from that breakpoint up they move next to the logo in the
17+
* single header row. The row heights come from `--sl-nav-height`, set
18+
* per breakpoint in custom.css; the logo row keeps the original height via
19+
* `--rs-nav-row`. The tabs live in src/data/nav.ts, shared with the Sidebar
20+
* override.
1921
*/
2022
2123
const shouldRenderSearch =
@@ -25,21 +27,9 @@ const shouldRenderSearch =
2527
const pathname = Astro.url.pathname;
2628
---
2729

28-
<div class="stacked">
29-
<div class="header">
30-
<div class="title-wrapper sl-flex">
31-
<SiteTitle />
32-
</div>
33-
<div class="search-wrapper sl-flex print:hidden">
34-
{shouldRenderSearch && <Search />}
35-
</div>
36-
<div class="sl-hidden md:sl-flex print:hidden right-group">
37-
<div class="sl-flex social-icons">
38-
<SocialIcons />
39-
</div>
40-
<ThemeSelect />
41-
<LanguageSelect />
42-
</div>
30+
<div class="header">
31+
<div class="title-wrapper sl-flex">
32+
<SiteTitle />
4333
</div>
4434
<nav class="top-nav print:hidden" aria-label="Main">
4535
{
@@ -53,6 +43,16 @@ const pathname = Astro.url.pathname;
5343
))
5444
}
5545
</nav>
46+
<div class="search-wrapper sl-flex print:hidden">
47+
{shouldRenderSearch && <Search />}
48+
</div>
49+
<div class="sl-hidden md:sl-flex print:hidden right-group">
50+
<div class="sl-flex social-icons">
51+
<SocialIcons />
52+
</div>
53+
<ThemeSelect />
54+
<LanguageSelect />
55+
</div>
5656
</div>
5757

5858
<script>
@@ -63,24 +63,21 @@ const pathname = Astro.url.pathname;
6363
</script>
6464

6565
{
66-
/* The first-row styles are copied from Starlight's Header.astro so the
67-
original layout survives the override; only `.stacked` and `.top-nav`
68-
are new. */
66+
/* The single-row styles are copied from Starlight's Header.astro so the
67+
original layout survives the override; only `.top-nav` and the wrapping
68+
behavior are new. */
6969
}
7070
<style>
71-
.stacked {
72-
display: flex;
73-
flex-direction: column;
74-
justify-content: space-between;
75-
height: 100%;
76-
}
77-
71+
/* Two rows while stacked: the original header items on top, the tab row
72+
wrapped underneath and pushed to the header's bottom border. */
7873
.header {
7974
display: flex;
80-
gap: var(--sl-nav-gap);
75+
flex-wrap: wrap;
76+
gap: 0 var(--sl-nav-gap);
8177
justify-content: space-between;
8278
align-items: center;
83-
height: calc(var(--rs-nav-row) - 2 * var(--sl-nav-pad-y));
79+
align-content: space-between;
80+
height: 100%;
8481
}
8582

8683
.title-wrapper {
@@ -105,6 +102,9 @@ const pathname = Astro.url.pathname;
105102

106103
.top-nav {
107104
display: flex;
105+
order: 5;
106+
flex-basis: 100%;
107+
min-width: 0;
108108
gap: 1.5rem;
109109
overflow-x: auto;
110110
scrollbar-width: none;
@@ -137,10 +137,38 @@ const pathname = Astro.url.pathname;
137137
search to the right edge, next to the other controls, keeps it in
138138
the same place everywhere. */
139139
grid-template-columns: auto 1fr auto;
140-
align-content: center;
140+
align-content: space-between;
141+
}
142+
.top-nav {
143+
grid-column: 1 / -1;
144+
grid-row: 2;
141145
}
142146
.search-wrapper {
143147
justify-content: flex-end;
144148
}
145149
}
150+
151+
/* Wide screens: one row, tabs between the logo and the search box. The
152+
tabs stretch to the full header height (the negative margins eat the
153+
header padding) so the active underline still touches the bottom
154+
border. Below 60rem the search box gets too cramped next to the tabs;
155+
keep this breakpoint in sync with --sl-nav-height in custom.css. */
156+
@media (min-width: 60rem) {
157+
.header {
158+
grid-template-columns: auto auto 1fr auto;
159+
}
160+
.top-nav {
161+
grid-column: 2;
162+
grid-row: 1;
163+
align-self: stretch;
164+
align-items: stretch;
165+
margin-block: calc(-1 * var(--sl-nav-pad-y));
166+
overflow-x: visible;
167+
}
168+
.top-nav a {
169+
display: inline-flex;
170+
align-items: center;
171+
padding-block: 0;
172+
}
173+
}
146174
</style>

‎src/styles/custom.css‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
--sl-font-mono: "JetBrains Mono";
2626
}
2727

28-
/* The header holds two rows: Starlight's original row (--rs-nav-row) and the
29-
section-tab row below it (src/components/Header.astro). Everything that
30-
hangs off the header (sidebar, mobile TOC, drawer) follows automatically,
31-
because Starlight positions it all with --sl-nav-height. */
28+
/* Below 60em the header holds two rows: Starlight's original row
29+
(--rs-nav-row) and the section-tab row below it; from 60em up the tabs
30+
move into the original row and the header shrinks back to one row
31+
(src/components/Header.astro, where the breakpoint must stay in sync).
32+
Everything that hangs off the header (sidebar, mobile TOC, drawer)
33+
follows automatically, because Starlight positions it all with
34+
--sl-nav-height. */
3235
:root {
3336
--rs-nav-row: 3.5rem;
3437
--sl-nav-height: calc(var(--rs-nav-row) + 2.75rem);
@@ -38,6 +41,11 @@
3841
--rs-nav-row: 4rem;
3942
}
4043
}
44+
@media (min-width: 60em) {
45+
:root {
46+
--sl-nav-height: var(--rs-nav-row);
47+
}
48+
}
4149

4250
/* JetBrains Mono enables ligatures by default; keep code as plain glyphs. */
4351
code,

0 commit comments

Comments
 (0)