[CSS] ์์ ๋งฅ๋ฝ Stacking Context
TL;DR
- ๊ธฐ๋ณธ์ ์ผ๋ก ์์๋ค์ DOM ์์์ ๋ฐ๋ผ ์์ธ๋ค.
- positioned(position ≠ static) ์์๋ non-positioned(position = static) ์์๋ณด๋ค ์์ ์์ธ๋ค.
- positioned ์์๋ค ์ค
z-index
๊ฐ์ด ๋์์๋ก ์์ ์์ธ๋ค. - ์๋ก์ด ์์ ๋งฅ๋ฝ์ด ์์ฑ๋๋ฉด ์์ ์์๋ ํด๋น ๋งฅ๋ฝ ์์์ ์์๊ฐ ๊ฒฐ์ ๋๋ค.
์ค๋ช
์์ ๋งฅ๋ฝ(Stacking Context)์ HTML ์์๋ค์ ๊ฐ์์ z์ถ(๊น์ด) ๋ฐฉํฅ์ผ๋ก ๋ฐฐ์นํ๋ ๊ฐ๋ ์ด๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์์๋ค์ DOM ์์์ ๋ฐ๋ผ ์์ธ๋ค. ์ฆ, ๋ค์ ์ ์ํ ์์์ผ์๋ก ํ๋ฉด์์ ์์ ์์นํ๋ค.
position
์ ์ ์ฉํ ์์(positioned)๋ position
์ ์ ์ฉํ์ง ์์ ์์(non-positioned)๋ณด๋ค ์์ ์์ธ๋ค. positioned ์์๋ค ์ค์์ z-index
๊ฐ์ด ๋์์๋ก ์์ ์์ธ๋ค. ์ฐธ๊ณ ๋ก z-index
๋ positioned ์์์์๋ง ์๋ํ๋ค.
- positioned:
position
์์ฑ์ดstatic
์ด์ธ์ ๊ฐ์ ๊ฐ์ง๋ ์์ - non-positioned:
position
์์ฑ์ดstatic
์ธ ์์ position
์์ฑ์ ์ง์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐstatic
(non-positioned)z-index
์์ฑ์ ์ง์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐauto
์๋ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์์๋ ์๋ก์ด ์์ ๋งฅ๋ฝ์ ์์ฑํ๋ค. ๊ทธ๋ผ ์์ ์์๋ค์ ํด๋น ๋งฅ๋ฝ ๋ด์์๋ง ์์ ์์๊ฐ ๊ฒฐ์ ๋ผ์ ๋ถ๋ชจ์ ์์ ๋งฅ๋ฝ์ ๋ฒ์ด๋ ์ ์๊ฒ ๋๋ค. ๋๋ฌธ์ ์์ ์์์ z-index
๊ฐ ๋ถ๋ชจ ์์๋ณด๋ค ํฌ๋๋ผ๋ ๋ถ๋ชจ ์์๊ฐ ๋ค๋ฅธ ์์๋ค๋ณด๋ค ๋ค์ ์๋ค๋ฉด ์์ ์์ ์ญ์ ๋ค์ ๋ฐฐ์น๋๋ค.
position: fixed
ํน์position: sticky
position: relative
ํน์position: absolute
์ด๋ฉด์,z-index
์์ฑ์ดauto
๊ฐ ์๋ ๋display: flex
ํน์display: grid
์ด๋ฉด์,z-index
์์ฑ์ดauto
๊ฐ ์๋ ๋opacity
๊ฐ์ด 1 ๋ฏธ๋ง์ผ ๋transform
,filter
,backdrop-filter
๋ฑ ์์ฑ์ดnone
์ด ์๋ ๋
์์
<div style="position: relative; z-index: 1">
A ์์ (z-index: 1)
<div style="position: absolute; z-index: 999">
A-1 ์์ (z-index: 999)
</div>
</div>
<div style="position: relative; z-index: 2">
B ์์ (z-index: 2)
</div>
See the Pen ์์ ๋งฅ๋ฝ Stacking Context by ColorFilter (@colorfilter) on CodePen.
- ์ต์์ ์์ ๋งฅ๋ฝ: B ์์
z-index
> A ์์z-index
์ด๋ฏ๋ก B ์์๊ฐ ์์ ์์ - A ์์ ๋ด๋ถ์ ์์ ๋งฅ๋ฝ: A-1 ์์
z-index
> A ์์z-index
์ด๋ฏ๋ก A-1 ์์๊ฐ ์์ ์์ - ์ต์ข ์ ์ผ๋ก (์๋์ชฝ) A → A-1 → B (์์ชฝ) ์์๋ก ์์
๋ ํผ๋ฐ์ค
์์ ๋งฅ๋ฝ - CSS: Cascading Style Sheets | MDN
์์ ๋งฅ๋ฝ(stacking context)์ ๊ฐ์์ Z์ถ์ ์ฌ์ฉํ HTML ์์์ 3์ฐจ์ ๊ฐ๋ ํ์ ๋๋ค. Z์ถ์ ์ฌ์ฉ์ ๊ธฐ์ค์ด๋ฉฐ, ์ฌ์ฉ์๋ ๋ทฐํฌํธ ํน์ ์นํ์ด์ง๋ฅผ ๋ฐ๋ผ๋ณด๊ณ ์์ ๊ฒ์ผ๋ก ๊ฐ์ ํฉ๋๋ค. ๊ฐ๊ฐ์ HTML ์์๋
developer.mozilla.org
๊ธ ์์ ์ฌํญ์ ๋ ธ์ ํ์ด์ง์ ๊ฐ์ฅ ๋น ๋ฅด๊ฒ ๋ฐ์๋ฉ๋๋ค. ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด ์ฃผ์ธ์
'๐ช Programming' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[CSS] :focus, :focus-visible ์ฐจ์ด์ (1) | 2025.03.06 |
---|---|
[JS] ์๋ฐ์คํฌ๋ฆฝํธ ๋๋ค ์์(Random Color) ์์ฑํ๊ธฐ (0) | 2025.03.04 |
[React] ๋ฆฌ์กํธ 19 ์ ๋ฐ์ดํธ ๋ด์ฉ ํบ์๋ณด๊ธฐ (0) | 2025.02.08 |
[Next.js] Dynamic Routes ๋ค์ด๋๋ฏน ๋ผ์ฐํธ (0) | 2025.01.31 |
[Next.js] App Router ๊ณต์ ํํ ๋ฆฌ์ผ ํบ์๋ณด๊ธฐ (1) | 2025.01.30 |
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote
๋ค๋ฅธ ๊ธ
-
[CSS] :focus, :focus-visible ์ฐจ์ด์
[CSS] :focus, :focus-visible ์ฐจ์ด์
2025.03.06 -
[JS] ์๋ฐ์คํฌ๋ฆฝํธ ๋๋ค ์์(Random Color) ์์ฑํ๊ธฐ
[JS] ์๋ฐ์คํฌ๋ฆฝํธ ๋๋ค ์์(Random Color) ์์ฑํ๊ธฐ
2025.03.04 -
[React] ๋ฆฌ์กํธ 19 ์ ๋ฐ์ดํธ ๋ด์ฉ ํบ์๋ณด๊ธฐ
[React] ๋ฆฌ์กํธ 19 ์ ๋ฐ์ดํธ ๋ด์ฉ ํบ์๋ณด๊ธฐ
2025.02.08 -
[Next.js] Dynamic Routes ๋ค์ด๋๋ฏน ๋ผ์ฐํธ
[Next.js] Dynamic Routes ๋ค์ด๋๋ฏน ๋ผ์ฐํธ
2025.01.31