CSS에서 position: absolute를 적용하면 해당 요소는 문서 흐름에서 제거되며, 특정 기준점을 기준으로 배치됩니다.
이때 기준점이 되는 요소는 가장 가까운 position이 지정된(즉, relative, absolute, fixed 중 하나인) 부모 요소입니다.
만약 부모 요소가 position: static(기본값)이라면, absolute 요소는 <html> 요소(즉, 문서 전체)를 기준으로 배치됩니다.
.parent {
width: 300px;
height: 300px;
background-color: lightblue;
}
.child {
position: absolute;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
background-color: red;
}<div class="parent">
<div class="child"></div>
</div>이 경우 .child 요소는 문서 전체를 기준으로 top: 50px, left: 50px 위치에 배치됩니다.
부모 요소에 position: relative를 설정하면, 해당 부모가 자식 요소의 기준점이 됩니다.
즉, absolute 요소는 문서가 아닌 부모 요소를 기준으로 배치됩니다.
.parent {
position: relative; /* 부모 요소를 기준점으로 만듦 */
width: 300px;
height: 300px;
background-color: lightblue;
}
.child {
position: absolute;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
background-color: red;
}<div class="parent">
<div class="child"></div>
</div>이제 .child 요소는 .parent 요소를 기준으로 top: 50px, left: 50px 위치에 배치됩니다.
부모 요소가 position: static이면 .child 요소는 <html>을 기준으로 배치됩니다. 따라서 원하는 위치에 정확히 배치하려면 부모 요소에 position: relative를 추가해야 합니다.
| 자식 요소 ( position: absolute) | 부모 요소 ( position) | 기준점 |
|---|---|---|
absolute | static (기본값) | <html>(문서 전체) |
absolute | relative | 부모 요소 |
absolute | absolute | 부모 요소 |
absolute | fixed | 뷰포트(화면) |
즉, 부모에 relative를 주면 absolute 요소가 해당 부모를 기준으로 배치되는 것이 핵심입니다.
부모 요소가 position: relative지만 height를 지정하지 않으면, 내부 absolute 요소가 부모의 크기를 결정하지 않으므로 의도한 대로 배치되지 않을 수 있습니다.
.parent {
position: relative;
background-color: lightblue;
}
.child {
position: absolute;
bottom: 0;
right: 0;
width: 100px;
height: 100px;
background-color: red;
}<div class="parent">
<div class="child"></div>
</div>이 경우 .parent 요소에 height가 지정되지 않으면, .child가 의도한 대로 배치되지 않을 수 있습니다.
✅ 해결 방법: 부모 요소에 height 값을 명시적으로 설정하거나, 내부 요소들의 높이를 기반으로 자동으로 설정되도록 해야 합니다.
.container {
position: relative;
width: 300px;
height: 300px;
background-color: lightgray;
}
.button {
position: absolute;
bottom: 10px;
right: 10px;
padding: 10px;
background-color: blue;
color: white;
}<div class="container">
<button class="button">버튼</button>
</div>✅ .button 요소가 .container 요소의 오른쪽 하단에 배치됩니다.
position: absolute는 부모 요소가 position: relative 이상일 때 해당 부모를 기준으로 배치됩니다.position: relative가 없으면 문서 전체(<html>)를 기준으로 배치됩니다.position: relative를 추가해야 합니다.absolute 요소는 문서 흐름에서 제거되므로 부모의 크기에 영향을 주지 않습니다.https://youtu.be/n8-wlkZiqio 1. 개요 NFS(Network File System)를 설치하고, rw/ro 및 root_squash 옵션에 따른 접근 제어와 성능을 테스트하는 방법을 정리한 가이드입니다.…
https://youtu.be/4MVxzmepY3s 1. 개요 리눅스에서 정기적으로 실행되는 작업(백업, 로그 정리, 모니터링 등)은 cron 서비스를 통해 자동화할 수 있습니다.…
https://youtu.be/vPfxWFBE1yc 1. 개요 리눅스 서버를 운영할 때 사용자 계정 생성, 비밀번호 설정, 권한 부여, 계정…
https://youtu.be/Gvp2XwBfoKw 1. 개요 리눅스 서버에서는 시스템 시간(OS 시간) 과 하드웨어 시간(RTC, Real-Time Clock) 을 동기화하는 것이 매우 중요합니다. 클러스터…
https://youtu.be/pt9qhawl8LY 1. 개요 리눅스 서버에서는 시스템 시간(OS 시간) 과 하드웨어 시간(RTC, Real-Time Clock) 을 모두 관리할 수 있습니다. 운영체제의…
https://youtu.be/iPdHGXh7DUg 1. 개요 서버 운영 시 시스템 시간이 올바르게 설정되어 있지 않으면 로그 분석, 모니터링,…