CSS 박스 모델(Box Model)이란?

웹 브라우저 > 개발자도구 > Computed 탭에서 박스모델을 확인 가능

웹 브라우저 > 개발자도구 > Computed 탭에서 박스모델을 확인 가능

인라인 레벨(Inline Level) 요소와 블록 레벨(Block Level) 요소

Untitled

<!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>
		.line {
			border: 3px solid black;
			margin: 10px;
		}
	</style>
</head>
<body>
	<span class="line">span 태그</span>
	<img class="line" src="./test.PNG" alt="">
	<strong class="line">strong 태그</strong>
	<h1 class="line">h1 태그</h1>
	<div class="line">div 태그</div>
	<p class="line">p 태그</p>
</body>
</html>

box-sizing

<!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>
		div {
			width: 150px;
			height: 150px;
			border: 5px solid #000;
			padding: 20px;
			margin: 10px;
			background-color: antiquewhite;
		}
		.div-1 {
			box-sizing: border-box;
		}
		.div-2 {
			box-sizing: content-box;
		}
	</style>
</head>
<body>
	<div class="div-1">박스 모델 div(border-box)</div>
	<div class="div-2">박스 모델 div(content-box)</div>
</body>
</html>

Untitled

width와 height

<!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">
	<link rel="stylesheet" href="./07_99_tng2_total1.css">
	<title>Document</title>
	<style>
		body {
			width: 100vw;
			height: 100vh;
		}
		div {
			border: 5px solid #000;
			padding: 20px;
			margin: 10px;
			background-color: antiquewhite;
		}
		.div-1 {
			width: 150px;
			height: 150px;
		}
		.div-2 {
			width: 30%;
			height: 30%;
		}
	</style>
</head>
<body>
	<div class="div-1">고정 길이 단위</div>
	<div class="div-2">상대 길이 단위</div>
</body>
</html>

Untitled

Untitled