<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
main, div {
padding: 20px;
}
main {
background-color: rgb(241, 164, 181);
width: 300px;
}
.div_static {
background-color: rgb(119, 136, 153);
position: static;
}
.div_static:nth-of-type(2) {
position: static;
background: rgb(0, 255, 255);
}
</style>
</head>
<body>
<main>
main
<div class="div_static">static</div>
<div class="div_static">static</div>
<div class="div_static">static</div>
</main>
</body>
</html>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
main, div {
padding: 20px;
}
main {
background-color: rgb(241, 164, 181);
width: 300px;
}
.div_static {
background-color: rgb(119, 136, 153);
position: static;
}
.div_relative1 {
background-color: rgb(182, 102, 102);
position: relative;
}
.div_relative2 {
background-color: rgb(133, 211, 146);
position: relative;
top: 30px;
left: 50px;
}
</style>
</head>
<body>
<main>
main
<div class="div_static">static</div>
<div class="div_relative1">div_relative1</div>
<div class="div_relative2">div_relative2</div>
</main>
</body>
</html>
div_relative2의 원래 위치

top와 left 속성을 지정한 후 div_relative2의 위치

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
main, section, div {
padding: 20px;
}
main {
background-color: rgb(241, 164, 181);
width: 300px;
}
section {
background-color: rgb(106, 173, 104);
position: relative;
}
.div_static {
background-color: rgb(119, 136, 153);
position: static;
}
.div_relative {
background-color: rgb(103, 112, 240);
position: relative;
}
.div_absolute {
background-color: dimgrey;
position: absolute;
top: 10px;
left: 100px;
}
</style>
</head>
<body>
<main>
main
<section>
section
<div class="div_static">static</div>
<div class="div_relative">div_relative</div>
<div class="div_absolute">div_absolute</div>
</section>
</main>
</body>
</html>
absolute 값 지정 전

absolute 값 지정 후

section 태그와 클래스 div_relative 태그에 relative를 설정했으나, 상위 요소인 section을 기준으로 위치가 지정 됨
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
main, div {
padding: 20px;
}
main {
background-color: rgb(241, 164, 181);
width: 300px;
height: 1000px;
}
.div_static {
background-color: rgb(119, 136, 153);
position: static;
}
.div_fixed {
background-color: dimgrey;
position: fixed;
bottom: 20px;
right: 20px;
}
</style>
</head>
<body>
<main>
main
<div class="div_static">static</div>
<div class="div_static">static</div>
<div class="div_fixed">div_fixed</div>
</main>
</body>
</html>
fixed 지정 전

fixed 지정 후, 뷰포트를 기준으로 위치를 지정

