9. position - static, relative, absoulte, fixed

김해준's avatar
Jan 13, 2026
9. position - static, relative, absoulte, fixed
CSS position은 요소의 배치 기준과 이동 방식을 결정하는 속성이다.
레이아웃의 주력 도구라기보다는, 특정 상황을 해결하기 위한 보조 수단에 가깝다.

📌 position이 필요한 이유

기본적으로 HTML 요소는 문서 흐름(normal flow) 에 따라 배치된다.
  • 위 → 아래
  • 왼쪽 → 오른쪽
  • 앞 요소의 위치가 뒤 요소에 영향을 줌
하지만 다음과 같은 상황에서는 기본 흐름만으로는 부족하다.
  • 요소를 겹치고 싶을 때
  • 특정 위치에 고정하고 싶을 때
  • 부모 기준으로 정확한 좌표를 잡고 싶을 때
이때 사용하는 것이 position이다.

1️⃣ position: static (기본값)

notion image
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <h1>position static, relative, absoulte, fixed</h1> <hr /> <!-- 기본 베이스가 static --> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>
position: static;
모든 요소의 기본값
문서 흐름을 그대로 따른다
top, left, right, bottom 적용되지 않음
👉 아무 설정 안 한 상태 = static

static 예제 특징

  • inline-block으로 나열
  • 요소 간 겹침 없음
  • 좌표 개념 없음
static은 “위치 제어를 하지 않겠다”는 선언이다.

2️⃣ position: relative

notion image
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <h1>position static, relative, absoulte, fixed</h1> <hr /> <!-- 기본 베이스가 static --> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>

핵심 개념

  • 자기 자신이 원래 있던 위치 기준으로 이동
  • 이동해도 원래 자리의 공간은 유지
👉 겉보기엔 움직였지만,
👉 레이아웃 상 자리는 그대로 남아 있다.

relative의 가장 중요한 용도

❗ absolute의 기준점 역할
.parent { position: relative; }
이 한 줄 때문에,
자식 absolute의 기준이 부모로 바뀐다.

3️⃣ position: absolute

notion image
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Document</title> <style> * { padding: 0px; margin: 0px; } .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; /* 새로운 도화지를 그림 */ /* 위치는 기존의 자기자리 */ position: absolute; /* 새로운 도화지엔 앞에 그려진 그림이 없기에 left, bottom 등을 통해 위치를 이동 시 자기 자리를 기준으로 움직이는것이 아닌 화면 전체 기준으로 이동함 상하/좌우 중 하나만 설정을 하면 나머지 하나의 값은 기존 값을 따라가기에 화면의 배치가 바뀔 시 위치가 틀어질 위험이 있어 상하/좌우 두값을 설정해줘야 흔들리지 않음*/ left: 300px; bottom: 30px; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; } </style> </head> <body> <h1>position static, relative, absoulte, fixed</h1> <hr /> <!-- absoulte --> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> </body> </html>

핵심 개념

  • 문서 흐름에서 제거
  • 새로운 “도화지” 위에 그려짐
  • 다른 요소의 배치에 영향을 주지 않음

absolute의 기준점

absolute는 항상 기준점을 찾는다.
  1. 가장 가까운 position: relative 부모
  1. 없다면 → viewport(화면 전체)

absolute의 특징 정리

항목
설명
문서 흐름
❌ 제거됨
겹침
가능
기준
relative 부모 or viewport
용도
겹침 UI, 내부 배치

4️⃣ relative + absolute 전략 (핵심 패턴)

notion image
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Document</title> <style> * { padding: 0px; margin: 0px; } .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } /* relative-absolute 전략 */ .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; position: relative; top: 50px; left: 50px; } .box5 { width: 200px; height: 200px; background-color: bisque; display: inline-block; position: absolute; top: 100px; left: 100px; } </style> </head> <body> <h1>position static, relative, absoulte, fixed</h1> <hr /> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"> <div class="box5"></div> </div> </body> </html>

이 전략의 의미

  • .box가 좌표 기준
  • .new_paper는 부모 내부에서 자유 이동
👉 보편적으로 가장 많이 쓰이는 position 패턴

실무 예시

  • input 안 아이콘
  • 카드 뱃지
  • 이미지 위 버튼
  • 말풍선 UI

relative-absolute 전략 예시

notion image
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .my_input { height: 100px; } .box { border: 1px solid black; padding: 5px; position: relative; } .new_paper { position: absolute; left: 20px; top: 20px; } .color_box { width: 100px; height: 100px; background-color: aqua; border: 1px solid black; } </style> </head> <body> <div class="color_box">1</div> <div class="box"> <div class="new_paper">🛻</div> <input class="my_input" type="text" /> </div> </body> </html>

5️⃣ position: fixed

notion image
notion image
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Document</title> <style> .box1 { width: 300px; height: 300px; background-color: yellow; display: inline-block; } .box2 { width: 300px; height: 300px; background-color: red; display: inline-block; } .box3 { width: 300px; height: 300px; background-color: green; display: inline-block; } .box4 { width: 300px; height: 300px; background-color: blue; display: inline-block; } .box5 { width: 300px; height: 300px; background-color: bisque; display: inline-block; /* fixed는 화면 위치에 고정된다 */ position: fixed; right: 20px; top: 20px; } </style> </head> <body> <h1>position static, relative, absoulte, fixed</h1> <!-- fixed --> <hr /> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> <div class="box5"></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> </body> </html>

핵심 개념

  • viewport(화면) 기준으로 고정
  • 스크롤을 해도 위치가 변하지 않음
  • 문서 흐름에서 제거됨

fixed의 특징

항목
설명
기준
viewport
스크롤
영향 없음
겹침
항상 위에 있음
용도
전역 UI

fixed 예제 결과 해석

  • 페이지를 스크롤해도
  • 베이지색 박스는 항상 같은 화면 위치
  • 다른 요소와 완전히 독립

6️⃣ absolute vs fixed 비교 (중요)

항목
absolute
fixed
기준
relative 부모
viewport
스크롤
따라 움직임
고정
사용 범위
컴포넌트 내부
전역 UI
실무 예
카드 버튼
플로팅 버튼

7️⃣ position 사용 시 주의사항

  • position은 레이아웃의 주인공이 아니다
  • Grid / Flex로 구조를 잡고
    • → position은 예외 처리용
❌ 모든 레이아웃을 position으로 해결하려 하지 말 것
⭕ “겹침 / 고정 / 기준 좌표”에만 사용

🔥 요약 패턴

카드 내부 아이콘

.card {position: relative; } .icon {position: absolute;top:8px;right:8px; }

플로팅 버튼

.fab { position: fixed; bottom:20px; right:20px; }

✨ 요약

position은 레이아웃 도구가 아니라 “위치를 예외적으로 조작하는 도구”다
 
Share article