position vs display κ΄κ³ μμ½νposition κ° |
μ¬μ© μλ μμ½ | μμ£Ό ν¨κ» μ°λ display |
μ€λͺ |
|---|---|---|---|
static |
κΈ°λ³Έκ° | block, inline, etc. |
κΈ°λ³Έ νλ¦μ λ°λΌ λ°°μΉλ¨. top/left λ± λ¬΄μλ¨. |
relative |
μκΈ° κΈ°μ€ μ΄λ | block, inline, etc. |
μλ μμΉλ₯Ό κΈ°μ€μΌλ‘ μ΄λ. z-index μ€μ κ°λ₯. |
absolute |
λΆλͺ¨ κΈ°μ€ μ΄λ | 무μλ¨ (μ¬μ€μ λΈλ‘μ²λΌ λμ) | κ°μ₯ κ°κΉμ΄ position: relative/absolute/fixed λΆλͺ¨ κΈ°μ€μΌλ‘ μμΉ μ§μ λ¨. DOM νλ¦μμ λΉ μ§. |
fixed |
νλ©΄ κΈ°μ€ κ³ μ | 무μλ¨ (viewport κΈ°μ€ μμΉ) | μ€ν¬λ‘€ν΄λ κ³ μ λ¨. νμ νλ©΄ κΈ°μ€. |
sticky |
μ€ν¬λ‘€ λ°λΌκ° + κ³ μ λ¨ | block, table, etc. |
μ€ν¬λ‘€ μμΉμ λ°λΌ relative β fixedμ²λΌ λ³ν¨. λΆλͺ¨ λμ΄ μν₯ λ°μ. |
absolute, fixed, stickyλ displayμ μν₯μ κ±°μ μ λ°μ.
μ¦ displayκ° λλ μκ΄μμ΄ λ μ΄μμμμ λΉ μ§κ³ μμ λ‘κ² μμΉ μ‘μ.
static, relativeλ κΈ°λ³Έ λ μ΄μμ νλ¦μ λ¨μ μμ΄μ displayλ λ λ°μ νκ² μμ©ν΄.
absolute μμλ blockμ²λΌ 보μ΄μ§λ§ μ€μ λ‘λ display: inlineμ΄μ΄λ blockμ²λΌ λμν¨.
κ·Έλμ λ³λλ‘ display: blockμ μ€ νμλ μμ.
| μμ± | IE μ§μ μ¬λΆ |
|---|---|
position: sticky |
β IE λ―Έμ§μ |
λλ¨Έμ§ (static, relative, absolute, fixed) |
β IE μμ μ§μ |
position: absolute vs position: static<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<title>Position vs Display</title>
<style>
.container {
position: relative;
width: 300px;
height: 200px;
background-color: #eee;
border: 2px solid #ccc;
margin-bottom: 20px;
}
.static-box {
display: inline-block;
background-color: skyblue;
padding: 10px;
}
.absolute-box {
position: absolute;
top: 20px;
left: 100px;
background-color: hotpink;
color: white;
padding: 10px;
/* display: inline-block; <- μμ΄λ μλ―Έ μμ */
}
</style>
</head>
<body>
<h2>Static μμ (κΈ°λ³Έ νλ¦)</h2>
<div class="container">
<div class="static-box">Box 1</div>
<div class="static-box">Box 2</div>
</div>
<h2>Absolute μμ (λΆλͺ¨ κΈ°μ€ μμΉ μ΄λ)</h2>
<div class="container">
<div class="static-box">Box 1</div>
<div class="absolute-box">Box 2 (absolute)</div>
</div>
</body>
</html>
display: inline-blockμ΄κ³ position: staticμ΄λΌμ νλ¦λλ‘ μ’βμ°λ‘ μμ¬.position: absoluteλΌμ νλ¦μμ λΉ μ§κ³ , λΆλͺ¨ .containerλ₯Ό κΈ°μ€μΌλ‘ (top: 20px, left: 100px)μ μμΉν¨.displayλ absoluteμΌ λ μ¬μ€μ 무μλ¨. inline, block, inline-block λ€ λ£μ΄λ λ°μ€μ²λΌ 보μ΄κ³ μμΉμ μν₯ μμ.