<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>block ์์ฑ์ ์๋ ์ข์ฐ ๋ ๋ค ์ฐจ์งํ๋๋ฐ</div>
<div class="hasWidth">width๊ฐ ๋ถ์ฌ๋๋ฉด ๋์ด๋์ง ์๊ฒ ๋ฉ๋๋ค.</div>
<div class="hasWidth center">์ค์์ผ๋ก ์๋?</div>
</body>
</html>
div {
margin-bottom: 20px;
}
.divColor{
background-color: yellow;
}
.hasWidth {
width: 150px;
}
.center {
margin: 20px auto;
}
block ์์์ width๋ฅผ ์ฃผ๊ฒ ๋๋ฉด block ์์ฑ์ด ์ฌ๋ผ์ง๋ค.
๋ํ ์ด ๋ margin์ ํ๋กํผํฐ ๊ฐ์ auto๋ก ์ฃผ๊ฒ ๋๋ฉด ๊ฐ์ด๋ฐ ์ ๋ ฌ์ด ๋๋ค.
margin๊ณผ padding์ ๋ํด์ ์ฒ์ ๋ฐฐ์ธ ๋, ํ๋กํผํฐ ๊ฐ์ ๋ค ๊ฐ ์ฃผ๊ฒ ๋๋ฉด
์๋์ผ๋ก ์/์ค๋ฅธ/์๋/์ผ ์์ผ๋ก ๊ฐ์ด ์ ์ฉ๋๋ค๊ณ ๋ฐฐ์ ๋ค.
์ถ๊ฐ๋ก ๊ฐ์ ๋๊ฐ๋ง ์ฃผ๊ฒ ๋๋ฉด ์์๋(์ธ๋ก)/์ค๋ฅธ์ผ(๊ฐ๋ก) ์์ผ๋ก ๊ฐ์ด ์ ์ฉ๋๋ค.
๋ฐ๋ผ์ ์ ์ฌ์ง์ center ํด๋์ค์ ๊ฒฝ์ฐ์ฒ๋ผ margin ๊ฐ์ 20px auto๋ฅผ ์ฃผ๋ฉด ์์๋ ๋ง์ง์ 20px์ฉ, ์ค๋ฅธ์ชฝ๊ณผ ์ผ์ชฝ ๋ง์ง์ ์๋์ผ๋ก ๋ค์ด๊ฐ ๊ฐ์ด๋ฐ ์ ๋ ฌ์ด ๋๋ค.