πŸ“Š 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처럼 변함. λΆ€λͺ¨ 높이 영ν–₯ λ°›μŒ.

⚠️ λΈŒλΌμš°μ € 지원


πŸ’‘ μ°Έκ³  사항


속성 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>


🧠 μš”μ  정리