position은 요소의 위치를 지정하는 속성
html code
<div class="container-1">
<div class="first">first</div>
<div class="second">second</div>
<div class="third">third</div>
</div>
css code
div {
border: 1px solid black;
box-sizing: border-box;
}
.container-1 {
border: 2px dashed red;
position: relative;
}
.first {
width: 300px;
height: 300px;
background-color: yellow;
}
.second {
width: 200px;
height: 200px;
background-color: green;
position: absolute;
top: 50px;
left: 50px;
}
.third {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top: 100px;
left: 100px;
}
position: relative; 안하면 요소를 안쪽으로 넣을 수 없음
position: absolute; 설정 안하면 아래로 차곡차곡 쌓임 안에 고정 안됨

html code
<div class="container-2">
<div id="center"></div>
</div>
css code
.container-2 {
width: 400px;
height: 400px;
position: relative;
}
#center {
width: 50px;
height: 50px;
background-color: pink;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
정가운데 배치 공식 같은 거

html code
<div class="fixed-area">
<a href="#body-top">위쪽으로 이동</a>
</div>
css
.fixed-area {
width: 120px;
position: fixed;
bottom: 50px;
right: 50px;
}

스크롤을 움직여도 항상 그 자리에 고정되어있음