์ง๋ ์๊ฐ์ CSS - float์ ๋ํด ๋ฐฐ์ ๋ค.
์ค๋์ float
์ ๊ด๋ จ๋ css ์์ฑ์ธ clear
์ ๋ํด์ ๋ฐฐ์๋ณด๊ณ ์ ํ๋ค.
์กฐ๊ธ ๋ ํ์ด ์๊ธฐํ๋ฉด, float๊ฐ ์ ์ฉ๋ ์์์ ๋ค์ ์์๊ฐ float์ ์ํฅ์ ๋ฐ์ ๋ฐฐ์น๋ ์ง, ์๋๋ฉด float์ ์ํฅ์์ ํด์ (clear)๋์ด ๋ฐฐ์น๋ ์ง๋ฅผ ์ ์ดํ๋ ๊ฒ์ด clear ์์ฑ์ ์ญํ ์ด๋ค.
๐ก ์์ (element)
- Document ์์ ๋ชจ๋ ๊ฐ์ฒด๊ฐ ์์ํ๋ ์ ์ผ ๋ฒ์ฉ์ ์ธ ๊ธฐ๋ฐ ํด๋์ค
- ๊ณตํต ๋ฉ์๋์ ์์ฑ๋ง ๊ฐ์ง๊ณ ์์
- ์์ :
<h1>์ ๋ชฉ์ ๋๋ค</h1>
floatElement {
float: left;
}
elementName,
.className,
#idName {
clear : none;
clear : left;
clear : right;
clear : both;
clear : initial;
clear : inherit;
}
clear ์์ฑ์ ๊ฐ์ผ๋ก๋ ์ด 6๊ฐ์ง๊ฐ ์๋ค.
๊ฐ ๊ฐ์ ๋ํ ์์ ์ ๊ฒฐ๊ณผ๊ฐ์ ์๋์์ ์์ธํ ์์๋ณด๊ณ ์ ํ๋ค.
<!DOCTYPE html>
<html>
<head>
<style>
.float {
float: left;
}
.clear {
clear: none;
}
</style>
</head>
<body>
<h1>The clear Property</h1>
<img class="float" src="https://i.pinimg.com/550x/b6/2b/56/b62b56a78f93ce5be9e68b291e45a8d8.jpg">
<p class="clear">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.float {
float: left;
}
.clear {
clear: left;
}
</style>
</head>
<body>
<h1>The clear Property</h1>
<img class="float" src="https://i.pinimg.com/550x/b6/2b/56/b62b56a78f93ce5be9e68b291e45a8d8.jpg">
<p class="clear">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
</body>
</html>
float๊ฐ left๋ก ์ง์ ๋์๊ธฐ ๋๋ฌธ์ clear๋ left๋ก ์ง์ ํ๋ค.
๋ง์ฝ float๊ฐ right์ธ ์ํ์ด๊ณ , clear๋ฅผ left๋ก ์ง์ ๋๋ฉด, ํ๋ฉด์์๋ float์ ๋ค์ ์์๋ฅผ ์ ์ดํ์ง ๋ชป ํ๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ clear:both
๋ฅผ ์ฌ์ฉํ ๊ฒ ์๋๋ผ๋ฉด, clear๋ float์ ์์ฑ๊ฐ์ ์ํฅ์ ๋ฐ๋๋ค.
<!DOCTYPE html>
<html>
<head>
<style>
.float {
float: right;
}
.clear {
clear: right;
}
</style>
</head>
<body>
<h1>The clear Property</h1>
<img class="float" src="https://i.pinimg.com/550x/b6/2b/56/b62b56a78f93ce5be9e68b291e45a8d8.jpg">
<p class="clear">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
</body>
</html>
float๊ฐ right๋ก ์ง์ ๋์๊ธฐ ๋๋ฌธ์ clear๋ right๋ก ์ง์ ํ๋ค.
๋ง์ฝ float๊ฐ left์ธ ์ํ์ด๊ณ , clear๋ฅผ right๋ก ์ง์ ๋๋ฉด, ํ๋ฉด์์๋ float์ ๋ค์ ์์๋ฅผ ์ ์ดํ์ง ๋ชป ํ๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ clear:both
๋ฅผ ์ฌ์ฉํ ๊ฒ ์๋๋ผ๋ฉด, clear๋ float์ ์์ฑ๊ฐ์ ์ํฅ์ ๋ฐ๋๋ค.
<!DOCTYPE html>
<html>
<head>
<style>
.float-left {
float: left;
}
.float-right {
float: right;
}
.clear {
clear: both;
}
</style>
</head>
<body>
<h1>The clear Property</h1>
<img class="float-left" src="https://i.pinimg.com/550x/b6/2b/56/b62b56a78f93ce5be9e68b291e45a8d8.jpg">
<img class="float-right" src="https://i.pinimg.com/550x/b6/2b/56/b62b56a78f93ce5be9e68b291e45a8d8.jpg" width="200" height="300">
<p class="clear">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
</body>
</html>
float๊ฐ ์ฌ๋ฌ๊ฐ ์ง์ ๋์ด ์๊ณ , clear:both
๋ฅผ ํ๋ฉด, height๊ฐ ๊ฐ์ฅ ํฐ float์ ๋ฐ์ผ๋ก ๋ค์ ์์๊ฐ ๋ฐฐ์น๋๋ค.