[CSS] clear

iamhyunjiยท2022๋…„ 6์›” 9์ผ
0
post-thumbnail

๐Ÿ” ๋“ค์–ด๊ฐ€๊ธฐ ์ „์—


์ง€๋‚œ ์‹œ๊ฐ„์— CSS - float์— ๋Œ€ํ•ด ๋ฐฐ์› ๋‹ค.
์˜ค๋Š˜์€ float์™€ ๊ด€๋ จ๋œ css ์†์„ฑ์ธ clear์— ๋Œ€ํ•ด์„œ ๋ฐฐ์›Œ๋ณด๊ณ ์ž ํ•œ๋‹ค.

๐Ÿ“Œ clear


  • float๊ฐ€ ์ ์šฉ๋œ ์š”์†Œ์˜ ๋‹ค์Œ ์š”์†Œ์˜ ํ๋ฆ„์„ ์ œ์–ด
  • float ๊ฐ’์— ๋”ฐ๋ผ clear ๊ฐ’ ์„ค์ •ํ•ด์•ผ float ์š”์†Œ์˜ ๋‹ค์Œ ์š”์†Œ ์ œ์–ด ๊ฐ€๋Šฅ
  • float ์†์„ฑ๊ฐ’์— ์˜ํ–ฅ ๋ฐ›์Œ

์กฐ๊ธˆ ๋” ํ’€์–ด ์–˜๊ธฐํ•˜๋ฉด, 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;
}
  • none
  • left
  • right
  • both
  • initial
  • inherit

clear ์†์„ฑ์˜ ๊ฐ’์œผ๋กœ๋Š” ์ด 6๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.
๊ฐ ๊ฐ’์— ๋Œ€ํ•œ ์˜ˆ์ œ์™€ ๊ฒฐ๊ณผ๊ฐ’์€ ์•„๋ž˜์—์„œ ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ณ ์ž ํ•œ๋‹ค.

none

  • ๊ธฐ๋ณธ๊ฐ’
  • float์˜ ๋‹ค์Œ ์š”์†Œ๊ฐ€ ํ•ด์ œ๋ฅผ ํ•˜์ง€ ์•Š์Œ
  • float์˜ ์˜ํ–ฅ ๊ทธ๋Œ€๋กœ ๋ฐ›์Œ
  • ์˜ˆ์ œ
<!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>
  • ๊ฒฐ๊ณผ
    clear: none

left

  • ์™ผ์ชฝ์œผ๋กœ float๋œ ์š”์†Œ ๋ฐ‘์œผ๋กœ ์š”์†Œ๊ฐ€ ๋ฐ€๋ ค์ง
  • ์˜ˆ์ œ
<!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>
  • ๊ฒฐ๊ณผ
    clear: left

float๊ฐ€ left๋กœ ์ง€์ •๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— clear๋„ left๋กœ ์ง€์ •ํ–ˆ๋‹ค.
๋งŒ์•ฝ float๊ฐ€ right์ธ ์ƒํƒœ์ด๊ณ , clear๋ฅผ left๋กœ ์ง€์ •๋˜๋ฉด, ํ™”๋ฉด์—์„œ๋Š” float์˜ ๋‹ค์Œ ์š”์†Œ๋ฅผ ์ œ์–ดํ•˜์ง€ ๋ชป ํ•œ๋‹ค.
๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— clear:both๋ฅผ ์‚ฌ์šฉํ• ๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด, clear๋Š” float์˜ ์†์„ฑ๊ฐ’์— ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค.

  • ์˜ค๋ฅธ์ชฝ์œผ๋กœ 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>
  • ๊ฒฐ๊ณผ
    clear: right

float๊ฐ€ right๋กœ ์ง€์ •๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— clear๋„ right๋กœ ์ง€์ •ํ–ˆ๋‹ค.
๋งŒ์•ฝ float๊ฐ€ left์ธ ์ƒํƒœ์ด๊ณ , clear๋ฅผ right๋กœ ์ง€์ •๋˜๋ฉด, ํ™”๋ฉด์—์„œ๋Š” float์˜ ๋‹ค์Œ ์š”์†Œ๋ฅผ ์ œ์–ดํ•˜์ง€ ๋ชป ํ•œ๋‹ค.
๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— clear:both๋ฅผ ์‚ฌ์šฉํ• ๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด, clear๋Š” float์˜ ์†์„ฑ๊ฐ’์— ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค.

both

  • ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ์œผ๋กœ float ์š”์†Œ ๋ฐ‘์œผ๋กœ ๋ฐ€๋ ค์ง
  • ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ๋ชจ๋‘ float ์š”์†Œ๊ฐ€ ์žˆ๋‹ค๋ฉด height๊ฐ€ ๋” ๋†’์€ ์š”์†Œ ๋ฐ‘์œผ๋กœ ๋ฐ€๋ฆผ
  • ์˜ˆ์ œ
<!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>
  • ๊ฒฐ๊ณผ
    clear: both

float๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์ง€์ •๋˜์–ด ์žˆ๊ณ , clear:both๋ฅผ ํ•˜๋ฉด, height๊ฐ€ ๊ฐ€์žฅ ํฐ float์— ๋ฐ‘์œผ๋กœ ๋‹ค์Œ ์š”์†Œ๊ฐ€ ๋ฐฐ์น˜๋œ๋‹ค.

๐Ÿ”— ์ฐธ๊ณ ยท์ถœ์ฒ˜


๐Ÿ‘€ ์Šค์Šค๋กœ ํ”ผ๋“œ๋ฐฑ


  • ์ง€์› ๋ธŒ๋ผ์šฐ์ € ์ •๋ณด๋„ ํ•จ๊ป˜ ํฌ์ŠคํŒ…๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Œ
profile
Lv0. ์›น ๊ฐœ๋ฐœ (โค๏ธโค๏ธโค๏ธ๐Ÿค)

0๊ฐœ์˜ ๋Œ“๊ธ€