본문 바로가기
기초 및 언어/▶ HTML & CSS

8. CSS_position

by 류딩이 2025. 9. 7.

1. static

<style type = "text/css">
	.box1, .box2, .box3{
		width : 200px;
		height : 200px;
	}
	.box1{
		/* 꼭짓점에서 20 30 떨어진 자리  */
		border : 3px solid red;
		position :static; 
		left : 20px;
		top : 30px;
	}
	.box2{
		border : 3px solid blue;
		position : static;
		left : 100px;
		top : 100px;
	}
	.box3{
		border : 3px solid green;
		position : static;
		left : 200px;
		top : 200px;
	}

</style>


</head>
<body>
	<div class = "box1"></div>
	<div class = "box2"></div>
	<div class = "box3"></div>
</body>

 

👉 아무 position을 주지 않으면, 모두 static 상태이고 HTML 작성 순서대로 위에서 아래로 쌓입니다.
이게 각 박스의 **“자기 자리”**

 


2. relative

<style type = "text/css">
	.box1, .box2, .box3{
		width : 200px;
		height : 200px;
	}
	.box1{
		/* 꼭짓점에서 20 30 떨어진 자리  */
		border : 3px solid red;
		position :relative; 
		left : 20px;
		top : 30px;
	}
	.box2{
		border : 3px solid blue;
		position : relative;
		left : 100px;
		top : 100px;
	}
	.box3{
		border : 3px solid green;
		position : relative;
		left : 200px;
		top : 200px;
	}

</style>


</head>
<body>
	<div class = "box1"></div>
	<div class = "box2"></div>
	<div class = "box3"></div>
</body>

 


3. absolute

<style type = "text/css">
	.box1, .box2, .box3{
		width : 200px;
		height : 200px;
	}
	.box1{
		/* 꼭짓점에서 20 30 떨어진 자리  */
		border : 3px solid red;
		position :absolute; 
		left : 20px;
		top : 30px;
	}
	.box2{
		border : 3px solid blue;
		position : absolute;
		left : 100px;
		top : 100px;
	}
	.box3{
		border : 3px solid green;
		position : absolute;
		left : 200px;
		top : 200px;
	}

</style>

<body>
	<div class = "box1"></div>
	<div class = "box2"></div>
	<div class = "box3"></div>
</body>

 

 


✅ 정리

  • 자기 자리 = static일 때 차지하는 원래 자리
  • relative: 자기 자리 기준으로 이동 (자리 차지 유지)
  • absolute: 자기 자리 버리고 부모 기준 이동 (자리 차지 없음)