position: static, relative, absolute, fixed
static - 문서의 흐름대로 배치하기
position의 기본값으로 요소를 나열한 순새대로 배치하며 top, right과 같은 소성은 사용할 수 없다.
relative - 문서 흐름 따라 위치 지정하기
static에서처럼 나열한 순서대로 배치되지만 top, right, bottom, left 속성을 사용 할수 있으며 좌표값을 사용해 위치를 지정할 수 있다.
<html>
<title>
</title>
<style>
.box1 {
display: inline-block;
width: 100px;
padding: 20px;
background: blue;
margin-right: 10px;
}
.box2 {
display: inline-block;
position: relative;
left: -50px;
top:30px;
width: 100px;
padding: 20px;
background: red;
margin-right: 10px;
}
</style>
<body>
<div id="relative">
<div class="box1"></div>
<div class="box2"></div>
</div>
</body>
</html>
<html>
<title>
</title>
<style>
#wrap {
position: relative; /* 기준이 되는 부모요소 */
width: 300px;
height: 300px;
border:1px solid #ccc
}
.box {
position: absolute; /* 위치를 지정할 작은 상자 */
width: 50px;
height: 50px;
background: blueviolet;
}
#card1 {
top: 0;
left: 0;
}
#card2 {
top:0;
right: 0;
}
#card3 {
top:100px;
right: 100px;
}
</style>
<body>
<div id="wrap">
<div class="box" id="card1"></div>
<div class="box" id="card2"></div>
<div class="box" id="card3"></div>
</div>
</body>
</html>