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
요소는 문서 흐름에서 제거되므로 부모의 크기에 영향을 주지 않습니다.1. 개요 본 글은 LVM의 스냅샷(snapshot) 기능으로 복구 지점 생성 → 파일 변경 → 스냅샷 병합(rollback) 과정을 실습합니다. 동일한…
https://youtu.be/ZcxB7akkDKs 1. 개요 두 개의 디스크(/dev/vdb, /dev/vdc)로 LVM을 구성하고, ext4·XFS 파일시스템 생성 → 마운트 → VG/LV 확장 → ext4 축소(오프라인)까지 전체…
https://youtu.be/XYBR1ZFrV9s 1. 개요 parted를 사용해 새 디스크에 GPT 라벨 생성 → 파티션 생성(ext4/XFS) → 포맷/마운트 →…
https://youtu.be/yYV8RQKCFzA 1. 개요 이 문서는 fdisk를 사용해 MBR(DOS) 디스크에 파티션을 생성하고, ext4/XFS 파일시스템을 포맷·마운트, /etc/fstab에 등록했다가, 안전하게 해제·삭제하는 전…
1. 개요 Linux에서 디스크 파티션 스타일은 MBR(Master Boot Record) 와 GPT(GUID Partition Table)에 대해 설명합니다. 2. MBR이란? 디스크…
https://youtu.be/CNd1bJV4wGY 1. 개요 Windows Server를 새로 설치할 때의 설치 과정을 단계별로 정리하였습니다. Windows Server 설치…