π positionμ΄λ?
- μμκ° μ΄λμ λ°°μΉλ μ§λ₯Ό κ²°μ νλ CSS μμ±
β
position μ’
λ₯
| μμ±κ° | κΈ°μ€μ | νΉμ§ | κ²ΉμΉ¨ κ°λ₯ |
|---|
static | μμ (κΈ°λ³Έ λ¬Έμ νλ¦) | κΈ°λ³Έκ°, μμΉ μ΄λ λΆκ° | β |
relative | μκΈ° μμ | μ리 μ μ§ + μ΄μ§ μ΄λ κ°λ₯ | β |
absolute | κ°μ₯ κ°κΉμ΄ position μ§μ μ‘°μ | λ¬Έμ νλ¦ νμΆ, μ νν μμΉ μ§μ κ°λ₯ | β
|
fixed | λΈλΌμ°μ (λ·°ν¬νΈ) | μ€ν¬λ‘€μλ κ³ μ λ¨ | β
|
sticky | μ€ν¬λ‘€λλ λΆλͺ¨ 컨ν
μ΄λ | μ‘°κ±΄λΆ κ³ μ (μ€ν¬λ‘€ μμΉμ λ°λΌ λ³ν¨) | β |

π» μμ
HTML
<section>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
CSS
section {
margin-top: 500px;
width: 200px;
height: 200px;
border: 10px solid red;
}
section > div {
width: 50%;
height: 25%;
position: absolute;
background-color: blue;
}
section > div:nth-child(1) { top: 0%; left: 0%; }
section > div:nth-child(2) { background: gold; top: 10%; left: 10%; }
section > div:nth-child(3) { background: pink; top: 20%; left: 20%; }
section > div:nth-child(4) { background: green; top: 30%; left: 30%; }
μ€ννλ©΄

β
μ λ° μ»¨νΈλ‘€μ μν κΈ°λ₯λ€
1) z-index
- κ²Ήμ³μ§ μμλ€ μ€ λκ° μμ 보μΌμ§λ₯Ό κ²°μ νλ μμ±
.element {
position: relative;
z-index: 10;
}
positionμ΄ staticμ΄ μλ κ²½μ°μλ§ μλ
z-indexλ νμ μμ κ°μλ§ λΉκ΅ κ°λ₯
- μ«μκ° ν΄μλ‘ μμ μμΉ (μμ κ°λ₯)
2) calc()
- CSSμμ κΈΈμ΄, ν¬κΈ° λ±μ μνμ μΌλ‘ κ³μ°ν μ μλ ν¨μ
width: calc(100% - 50px);
margin-top: calc(2rem + 10px);
- λ¨μ νΌν© κ°λ₯ (%, px, rem λ±)
- μ°μ°μ:
+, -, *, / κ°λ₯ (μ£Όμ: λμ΄μ°κΈ° νμ!)
- λ°μν λ μ΄μμ λ§λ€ λ μ μ©
- μμλ₯Ό νμ , μ΄λ, νλ/μΆμ, κΈ°μΈμ΄κΈ° λ± μκ°μ μΌλ‘ λ³ννλ μμ±
.element {
transform: translate(50px, 20px);
}
translate(x, y) : μμΉ μ΄λ
scale(x) : ν¬κΈ° νλ/μΆμ
rotate(deg) : νμ
skew(x, y) : κΈ°μΈμ΄κΈ°
matrix(...) : λ³΅ν© λ³ν