
์ปจํ ์ด๋ ๋ธ๋ก์ด๋ ์์์ ์์น์ ํฌ๊ธฐ๋ฅผ ์ง์ ํ๋ ๋ฐ ์ฌ์ฉํ๋ ๋ธ๋ก์ ์๋ฏธํฉ๋๋ค.
์ด๊ฒ ๋ฌด์จ ๋ง์ด๋๋ฉด ์๋์ ์ธ ๊ฐ์ด๋, ์์์ ์์น๋ฅผ ์ง์ ํ๋ ๊ธฐ์ค์ด ํ์ํ ๋ ์ฌ์ฉํ๋ค๋ ์๋ฏธํ๋๋ค.
์ด๊ฒ ๋ ๋ฌด์จ ๋ง์ด๋๋ฉด position: absoulte;๋ font-size: 2em;๊ฐ์ ๊ฐ์ ๊ฒฐ์ ํ๋ ๋ฐ ๊ธฐ์ค์ด ํ์ํ ์์ฑ๋ค์ ๊ธฐ์ค ์ฆ, ๋์์ ๊ฒฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ๋ ๊ฒ์ด ์ปจํ
์ด๋ ๋ธ๋ก์
๋๋ค.
position์ด absolute์ธ ๊ฒฝ์ฐ์๋ static์ ์ธํ ๊ฐ์ฅ ๊ฐ๊น์ด ์กฐ์position์ด fixed์ธ ๊ฒฝ์ฐ์๋ ๋ทฐํฌํธ<body>
<div class="outer">
outer
<div class="inner">width: 50%</div>
</div>
</body>
.outer {
position: static;
display: inline;
width: 100px;
height: 100px;
background-color: red;
}
.inner {
width: 50%;
background-color: blueviolet;
}
์ผ๋จ outer๋ display: inline;์ด๊ธฐ ๋๋ฌธ์ width๋ ๋ฌด์๋๊ณ ์์ ์ ํฌ๊ธฐ๋งํผ ์์ญ์ ์ฐจ์งํ๋ค.
๊ทธ๋ฆฌ๊ณ inner๋ outer๋ด๋ถ์ ์กด์ฌํ๋ฏ๋ก inner์ ์ปจํ
์ด๋ ๋ธ๋ก์ด outer๊ฐ ๋๊ณ outer์ width์ 50%๋งํผ ํฌ๊ธฐ๋ฅผ ์ฐจ์งํ๋ค๊ณ ์๊ฐํ ์ ์์ง๋ง ์ค์ ๋ก ์คํ์์ผ๋ณด๋ฉด ๋ทฐํฌํธ๋ฅผ ๊ธฐ์ค์ผ๋ก width๊ฐ์ด ๊ฒฐ์ ๋๋ค.
outer์ display: inline-block์ผ๋ก ๋ฐ๊พธ๋ฉด inner์ ์ปจํ
์ด๋ ๋ธ๋ก์ด outer๊ฐ ๋์ด 50px๋งํผ์ width๋ฅผ ์ฐจ์งํ๊ฒ ๋๋ค.