<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
body {
/* 스크롤바가 나타나개 하기 위해 높이값 설정 (fixed속성 체크) */
height: 1000px;
}
.wrap {
width: 300px;
height: 300px;
background-color: #fcd;
}
.box {
width: 100px;
height: 100px;
background-color: green;
border: 2px solid red;
}
/* relative 속성 */
.rel {
position: relative;
left: 50px;
top: 70px;
}
/* 위치 이동 없이 relative속성만 적용 */
.rel2 {
position: relative;
}
/* absolute 속성 */
.abs {
position: absolute;
left: 50px;
top: 70px;
}
/* fixed 속성 */
.fixed {
position: fixed;
right: 10px;
top: 100px;
}
</style>
</head>
<body>
<h2>relative</h2>
<div class="wrap">
<!-- 기본값 -->
<div class="box">relative Test1</div>
<!-- relative속성 적용, 현재 기본 위치를 기준으로 왼쪽에서 50만큼 위에서 70만큼 이동 -->
<div class="box rel">relative Test2</div>
</div>
<hr/>
<h2>absolute</h2>
<div class="wrap rel2">
<div class="box">absolute Test1</div>
<!-- absolute속성 적용, 부모태그의 왼쪽 상단을 기준으로 왼쪽에서 50만큼 위에서 70만큼 이동 -->
<div class="box abs">absolute Test2</div>
</div>
<!-- fixed속성 적용, 브라우저 화면을 기준으로 오른쪽에서 10만큼 위에서 100만큼 이동 -->
<div class="box fixed">fixed Test1</div>
</body>
</html>