Skip to content

Commit 74b6b2b

Browse files
committed
Add sticky headings for h2 and h3 elements with z-index adjustments for correct layering.
1 parent ce9152f commit 74b6b2b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/app.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,46 @@ export class App extends LitElement {
8484
error: string | null = null;
8585

8686
static styles = css`
87+
/* Sticky headings. */
8788
h2 {
8889
margin-top: 2rem;
90+
position: sticky;
91+
top: 0;
92+
background: var(--bg-color);
93+
margin: 0;
94+
padding: 1rem 0;
8995
}
96+
97+
/* First h2 gets z-index 10 */
98+
h2:nth-of-type(1) {
99+
z-index: 10;
100+
}
101+
102+
/* Second h2 gets z-index 30 */
103+
h2:nth-of-type(2) {
104+
z-index: 30;
105+
}
106+
107+
h3 {
108+
position: sticky;
109+
top: 3rem;
110+
background: var(--bg-color);
111+
margin: 0;
112+
padding: 0.5rem 0;
113+
}
114+
115+
/* First two h3s get z-index 20 */
116+
h3:nth-of-type(1),
117+
h3:nth-of-type(2) {
118+
z-index: 20;
119+
}
120+
121+
/* Last two h3s get z-index 40 */
122+
h3:nth-of-type(3),
123+
h3:nth-of-type(4) {
124+
z-index: 40;
125+
}
126+
90127
.error {
91128
color: red;
92129
}

0 commit comments

Comments
 (0)