[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
κΈ μμ μ¬νμ λ Έμ νμ΄μ§μ κ°μ₯ λΉ λ₯΄κ² λ°μλ©λλ€. λ§ν¬λ₯Ό μ°Έκ³ ν΄ μ£ΌμΈμ