Skip to content

Commit 0b81833

Browse files
committed
refactor: Reimplement position: fixed as position: sticky, to solve the awkward behavior of header elements sticking to the top when you pull down hard in iOS Safari,
1 parent 76911ca commit 0b81833

3 files changed

Lines changed: 46 additions & 49 deletions

File tree

layout/about.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<h1>개발자 차한음</h1>
6969
</div>
7070
</header>
71+
7172
<main class="about-content">
7273
<article class="markdown-body">
7374
{{ .Content }}

layout/styles/about.scss

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
.about-nav {
2-
position: fixed;
2+
position: sticky;
33
top: 0;
4-
left: 0;
5-
right: 0;
64
max-width: 35rem;
75
margin: 0 auto;
8-
96
z-index: 10;
7+
108
transition: background-color 0.3s ease;
119

1210
&.scrolled {
13-
// transition: background-color 0.3s ease;
1411
background-color: white;
1512

1613
a {
@@ -55,37 +52,35 @@
5552
}
5653

5754
.about-header {
55+
margin-top: -4rem;
56+
}
57+
58+
.about-hero {
5859
background-image:
5960
linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.5)),
6061
url('/assets/profile.webp'),
6162
url('/assets/profile.png');
6263
background-size: cover;
6364
background-position: center;
6465

65-
// 기존에는 header 자체에 이미지를 보여주고 있음.
66-
// header hieght는 nav + hero인 17.5 + 4임.
67-
// 그니까 Nav를 분리시키면, header height는 17.5로 작아짐.
66+
height: 21.5rem;
67+
@media (max-width: 35rem) {
68+
height: 19.5rem;
69+
}
6870

69-
.about-hero {
70-
height: 21.5rem;
71+
display: flex;
72+
flex-direction: column;
73+
justify-content: flex-end;
74+
75+
h1 {
76+
font-size: 2rem;
77+
line-height: 1.5;
78+
font-weight: 800;
79+
padding: 1rem;
7180
@media (max-width: 35rem) {
72-
height: 19.5rem;
73-
}
74-
75-
display: flex;
76-
flex-direction: column;
77-
justify-content: flex-end;
78-
79-
h1 {
80-
font-size: 2rem;
81-
line-height: 1.5;
82-
font-weight: 800;
83-
padding: 1rem;
84-
@media (max-width: 35rem) {
85-
padding: 1rem 1.3rem 1rem 1.3rem;
86-
}
87-
color: var(--neutral-100);
81+
padding: 1rem 1.3rem 1rem 1.3rem;
8882
}
83+
color: var(--neutral-100);
8984
}
9085
}
9186

layout/styles/home.scss

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// 기존에는 header 자체에 이미지를 보여주고 있음.
2+
// header hieght는 nav + hero인 17.5 + 4임.
3+
// 그니까 Nav를 분리시키면, header height는 17.5로 작아짐.
4+
15
.home-nav {
2-
position: fixed;
6+
position: sticky;
37
top: 0;
4-
left: 0;
5-
right: 0;
68
max-width: 35rem;
79
margin: 0 auto;
8-
910
z-index: 10;
10-
11+
1112
transition: background-color 0.3s ease;
1213
/*
1314
스크롤 내릴 때: transparent → white로 배경색이 변합니다. 이 전환은 부드럽고 보기 좋습니다.
@@ -66,33 +67,33 @@
6667
}
6768

6869
.home-header {
70+
margin-top: -4rem;
71+
}
72+
73+
.home-hero {
6974
background-image:
7075
linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.5)),
7176
url('/assets/profile.webp'),
7277
url('/assets/profile.png');
7378
background-size: cover;
7479
background-position: center;
7580

76-
.home-hero {
77-
height: 21.5rem;
81+
height: 21.5rem;
82+
@media (max-width: 35rem) {
83+
height: 19.5rem;
84+
}
85+
display: flex;
86+
flex-direction: column;
87+
justify-content: flex-end;
88+
h1 {
89+
font-size: 2rem;
90+
line-height: 1.5;
91+
font-weight: 800;
92+
padding: 1rem;
7893
@media (max-width: 35rem) {
79-
height: 19.5rem;
80-
}
81-
82-
display: flex;
83-
flex-direction: column;
84-
justify-content: flex-end;
85-
86-
h1 {
87-
font-size: 2rem;
88-
line-height: 1.5;
89-
font-weight: 800;
90-
padding: 1rem;
91-
@media (max-width: 35rem) {
92-
padding: 1rem 1.3rem 1rem 1.3rem;
93-
}
94-
color: var(--neutral-100);
94+
padding: 1rem 1.3rem 1rem 1.3rem;
9595
}
96+
color: var(--neutral-100);
9697
}
9798
}
9899

0 commit comments

Comments
 (0)