Skip to content

Commit da9ecfa

Browse files
committed
refactor: define scroll margin only in markdown
1 parent 32a4eda commit da9ecfa

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

website/src/mdx/markdown.module.scss

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
@use "@/styles/colors";
2+
@use "@/components/Navbar/styles.module" as navbar;
3+
4+
$navbar-height: navbar.$navbar-height;
25

36
/* markdown styles */
47
.markdown {
@@ -33,19 +36,27 @@
3336
/* apply these styles only in markdown "content" (i.e. articles) */
3437
&.content {
3538

39+
// don't let target be covered by navbar
40+
* {
41+
scroll-margin-top: $navbar-height;
42+
}
43+
3644
// heading margins
3745
h1, h2, h3, h4, h5, h6 {
38-
margin: 2em 0 1em;
39-
}
46+
$heading-margin-top: 2em;
4047

41-
// don't add margin to first child (the whole markdown container has top margin already)
42-
> *:first-child {
43-
margin-top: 0;
48+
margin: $heading-margin-top 0 1em;
49+
scroll-margin-top: calc(#{$navbar-height} + #{$heading-margin-top});
4450
}
4551

4652
// block margins
4753
> * {
48-
margin-bottom: 1rem;
54+
margin: 1rem;
55+
56+
// don't add margin to first child (the whole markdown container has top margin already)
57+
&:first-child {
58+
margin-top: 0;
59+
}
4960
}
5061
}
5162
}

website/src/mdx/markdown.module.scss.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2-
32
declare namespace MarkdownModuleScssNamespace {
43
export interface IMarkdownModuleScss {
54
content: string;
5+
hidden: string;
6+
left: string;
7+
logo: string;
68
markdown: string;
9+
navItem: string;
10+
navbar: string;
11+
right: string;
712
}
813
}
914

website/src/styles/index.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@use "./mixins";
2-
@use "@/components/Navbar/styles.module.scss" as navbar;
32

43
@import "./reset";
54
@import "./katex-0.15.2/katex.min.css";
@@ -9,10 +8,6 @@ html {
98
scroll-behavior: smooth;
109
}
1110

12-
* {
13-
scroll-margin-top: navbar.$navbar-height;
14-
}
15-
1611
body {
1712
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
1813
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;

0 commit comments

Comments
 (0)