Skip to content

Commit c3012a3

Browse files
Filmbostock
andauthored
fix scroll margin for anchor links; fix conditional header layout (#1685)
* fix links to anchors (e.g. https://observablehq.com/framework/files#static-analysis) * use scroll-padding-top instead * fix #1686; conditional header layout * move scroll-padding-top to default styles --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent c7dce79 commit c3012a3

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

docs/style.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
--theme-foreground-focus: #148576;
1010
}
1111

12-
h1,
13-
h2,
14-
h3,
15-
h4,
16-
h5,
17-
h6 {
18-
margin-top: revert;
19-
}
20-
2112
h1 code,
2213
h2 code,
2314
h3 code,

src/style/global.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ h6 {
3939
line-height: 1.15;
4040
margin-top: 0;
4141
margin-bottom: 0.25rem;
42-
scroll-margin-top: 1rem;
4342
text-wrap: balance;
4443
}
4544

src/style/layout.css

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
--theme-magnifier: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath stroke='currentColor' stroke-width='2' fill='none' d='M15,15L10.5,10.5a3,3 0 1,0 -6 -6a3,3 0 1,0 6 6'%3E%3C/path%3E%3C/svg%3E");
55
--observablehq-max-width: 1440px;
66
--observablehq-header-height: 2.2rem;
7+
scroll-padding-top: 2.5rem;
8+
}
9+
10+
:root:has(#observablehq-header) {
11+
scroll-padding-top: calc(var(--observablehq-header-height) + 2.5rem);
712
}
813

914
body {
@@ -35,12 +40,15 @@ body {
3540
}
3641

3742
#observablehq-main {
38-
margin-top: 0.67rem;
3943
min-height: calc(100vh - 20rem);
4044
position: relative;
4145
z-index: 0;
4246
}
4347

48+
#observablehq-header ~ #observablehq-main {
49+
margin-top: calc(var(--observablehq-header-height) + 1.5rem + 2rem);
50+
}
51+
4452
#observablehq-footer {
4553
display: block;
4654
margin-top: 10rem;
@@ -101,8 +109,7 @@ body {
101109
}
102110

103111
#observablehq-center {
104-
margin: 1rem 2rem;
105-
padding-top: calc(var(--observablehq-header-height) + 0.5rem);
112+
margin: 2rem;
106113
--observablehq-inset-left: 0rem;
107114
--observablehq-inset-right: 0rem;
108115
}
@@ -290,12 +297,16 @@ body {
290297
color: var(--theme-foreground-muted);
291298
font: 400 14px var(--sans-serif);
292299
z-index: 1;
293-
top: calc(var(--observablehq-header-height) + 1.5rem);
300+
top: 0;
294301
right: calc(max(0rem, (100% - var(--observablehq-max-width)) / 2) + 1rem);
295302
bottom: 0;
296303
overflow-y: auto;
297304
}
298305

306+
#observablehq-header ~ #observablehq-toc {
307+
top: calc(var(--observablehq-header-height) + 1.5rem);
308+
}
309+
299310
#observablehq-toc nav {
300311
width: 192px;
301312
margin: 2rem 0;

0 commit comments

Comments
 (0)