position 1편 relative absolute
position
- 문서 상에 요소를 배치하는 방법을 정의 (top, bottom, right, left)
- static : 기본값, 요소를 일반적인 문서 흐름에 따라 배치
- relative : 일반적인 문서 흐름, 상하좌우 위치 값에 따라 오프셋 적용
- absolute : 일반적인 문서 흐름 X, 가장 가까운 상위 요소의 position 지정 요소에 대한 오프셋 적용
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>position 1</title>
<style>
p{
width: 100px; height: 100px;
background-color: red;
position: relative;
left: 100px;
}
div{
width: 200px; height: 200px;
background-color: yellow;
position: relative;
border: 1px solid black;
}
.abs{
width: 100px; height: 100px;
background-color: red;
position: absolute;
top: 0px; left: 100px;
}
</style>
</head>
<body>
<p>p</p>
<hr>
<div></div>
<div>
<div class="abs"></div>
</div>
</body>
</html>
출처 : 유노코딩, 입문자를 위한 CSS 기초 강의