1) position
static : 기준 없음
relative : 요소 자신을 기준
absolute : 위치 상 부모 요소를 기준
fixed : 뷰포트(ViewPort) 기준
sticky : 스크롤 영역 기준
참고사항)
예시 전체코드)
.container {
width: 300px;
background-color: royalblue;
}
.container .item {
border: 1px dashed red;
background-color: orange;
}
.container .item:nth-child(1) {
width: 100px;
height: 100px;
}
.container .item:nth-child(2) {
width: 140px;
height: 70px;
position: relative;
top: 30px;
left: 60px;
}
.container .item:nth-child(3) {
width: 70px;
height: 120px;
}
(1) position: relative; (부모 요소)
.container .item:nth-child(2) {
width: 140px;
height: 70px;
position: relative;
top: 30px;
left: 60px;
}
(2) position: absolute; (자식 요소)
.container {
width: 300px;
background-color: royalblue;
position: relative;
}
...생략...
.container .item:nth-child(2) {
width: 140px;
height: 70px;
position: absolute;
top: 30px;
right: 30px;
}
2) 요소 쌓임 순서(Stack order)
예제)
.container .item:nth-child(1) {
position: relative;
z-index: 1;
}
.container .item:nth-child(2) {
position: absolute;
top: 50px;
left: 40px;
}
3) z-index
auto : 부모 요소와 동일한 쌓임 정도
숫자 : 숫자가 높을 수록 위에 쌓임