
position 은 요소를 원하는 위치로 배치할 수 있도록 하는 속성이다.
position: static | relative | absolute | fixed | sticky;
top, right, bottom, left 가 적용되지 않는다.position: relative;
top: 10px; <--! 위에서부터 10px 내려감 -->
right: 20px; <--! 오른쪽에서부터 20px 왼쪽으로 이동 -->
positive: static 이 아닌 요소를 기준으로 한다.absolute를 사용할 때는
부모 요소에 position: relative; 를 함께 설정한다.
.parent {
position: relative; <--! → 기준점을 꼭 설정해줘야 원하는 위치에 정확히 배치 가능 -->
}
.child {
position: absolute;
top: 0;
right: 0;
}
position: fixed;
bottom: 0;
position 과 함께 사용하는 속성:
top | right | bottom | left
left 또는 right 중 하나top 또는 bottom 중 하나요소의 쌓이는 순서를 결정하는 속성이다.
position 이 적용된 요소에서만 동작한다. (static 에서는 적용되지 않음)