๐Ÿค” ๋ธ”๋ก ์„œ์‹ ๋งฅ๋ฝ

๋ฐ•์ƒ์€ยท2021๋…„ 10์›” 8์ผ
0

๐Ÿช„ CSS ๐Ÿช„

๋ชฉ๋ก ๋ณด๊ธฐ
1/6
post-thumbnail

๐Ÿค” ๋ธ”๋ก ์„œ์‹ ๋งฅ๋ฝ ( Block Format Context )

๋ธ”๋ก ์„œ์‹ ๋งฅ๋ฝ์„ ์ดํ›„ BNF๋กœ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค.

  • MDN์ •์˜

    ๋ธ”๋ก ์„œ์‹ ๋งฅ๋ฝ(block format context)์€ ์›น ํŽ˜์ด์ง€๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ์‹œ๊ฐ์  CSS์˜ ์ผ๋ถ€๋กœ์„œ, ๋ธ”๋ก ๋ฐ•์Šค์˜ ๋ ˆ์ด์•„์›ƒ์ด ๋ฐœ์ƒํ•˜๋Š” ์ง€์ ๊ณผ ํ”Œ๋กœํŒ… ์š”์†Œ์˜ ์ƒํ˜ธ์ž‘์šฉ ๋ฒ”์œ„๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๋ฒ”์œ„์ž…๋‹ˆ๋‹ค.

์œ„์™€ ๊ฐ™์ด ์ •์˜๋˜์–ด ์žˆ์ง€๋งŒ ์ด ํ…์ŠคํŠธ๋งŒ ๋ณด๊ณ ๋Š” ๋ฌด์Šจ ์˜๋ฏธ์ธ์ง€ ์ „ํ˜€ ์•Œ ์ˆ˜ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

๊ตฌ๊ธ€๋งํ•ด์„œ ์—ฌ๋Ÿฌ ์ •๋ณด๋ฅผ ์ฐพ์•„๋ณธ ๊ฒฐ๊ณผ BNF๋Š” ์•„์ง ์ •ํ™•ํžˆ ๋ชจ๋ฅด๊ฒ ์œผ๋‚˜ ์‚ฌ์šฉ ์ด์œ ๋Š” ์–ด๋Š์ •๋„ ์ดํ•ดํ–ˆ๋‹ค.

  • ์‚ฌ์šฉ ์ด์œ 

    float๋กœ ์‚ฌ์šฉํ•˜๊ณ  ๋ถ€๋ชจ๊ฐ€ ์ž์‹์˜ ์˜์—ญ์„ ๋ชจ๋‘ ๋‹ด์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ์™€ ๋งˆ์ง„์ƒ์‡„๋ฅผ ์—†์• ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

1. ๋ถ€๋ชจ๊ฐ€ ์ž์‹์„ ๋ชจ๋‘ ๋‹ด์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ ( float์‚ฌ์šฉ )

  • html
<!-- ๋ชจ๋‘ ์ƒ๋žตํ•˜๊ณ  body๋ถ€๋ถ„๋งŒ ์ž‘์„ฑํ•จ -->
<body>
  <div class="container bnf">
    <div class="float__box">float-box!!</div>
    container!!
  </div>
</body>
  • css
.container {
  border: 5px dashed black;
  padding: 40px;
  margin: 10px;
}

.float__box {
  float: left;
  background-color: red;
  width: 100px;
  height: 500px;
  padding: 20px;
  margin: 10px;
  border: 5px dashed black;
}

.bnf {
  overflow: hidden;
}

์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๋กœ ์‹คํ–‰์‹œ์ผœ๋ณด๋ฉด container๊ฐ€ float__box๋ฅผ ๋ชจ๋‘ ๋‹ด์ง€ ๋ชปํ•ด float__box์˜ height๊ฐ€ container๋ณด๋‹ค ์ปค์ง€๊ฒŒ ๋œ๋‹ค.

์ด ๋•Œ bnf๋ฅผ container์˜ ํด๋ž˜์Šค์— ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด float__box๋ฅผ ํฌํ•จํ•œ ํฌ๊ธฐ๋งŒํผ ์ปค์ง€๊ฒŒ ๋œ๋‹ค.

2. ๋งˆ์ง„์ƒ์‡„ ์ œ๊ฑฐ

  • html
<body>
  <div class="top">top!</div>
  <!-- <div class="bnf"></div> -->
  <div class="bottom">bottom!!</div>
</body>
  • css
.top {
  padding: 10px;
  background-color: red;
  margin: 100px 0;
}

.bottom {
  padding: 10px;
  background-color: blue;
  margin: 100px 0;
}

.bnf {
  overflow: hidden;
}

css์˜ ๋งˆ์ง„์ƒ์‡„๋ผ๋Š” ํŠน์„ฑ๋•Œ๋ฌธ์— top๊ณผ bottom์— ๊ฐ๊ฐ ๋งˆ์ง„์„ ๋ถ€์—ฌํ–ˆ์ง€๋งŒ ๋งˆ์ง„๋ผ๋ฆฌ ๊ฒน์ณ์„œ 100px๋งŒํผ๋งŒ์˜ ๋งˆ์ง„์ด ์ƒ๊ธฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฐ ํ˜„์ƒ์„ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ๋Š” BNF๋ฅผ ์ ์šฉ์‹œํ‚ค๋ฉด ๋งˆ์ง„์ƒ์‡„ํ˜„์ƒ์ด ์—†์–ด์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์œ„์ฒ˜๋Ÿผ ๋งˆ์ง„์ƒ์‡„๊ฐ€ ์ผ์–ด๋‚˜๋Š” ํƒœ๊ทธ ์‚ฌ์ด์— BNF๋ฅผ ์ ์šฉ์‹œํ‚จ ํƒœ๊ทธ๋ฅผ ๋„ฃ์–ด์–ด ๋˜๊ณ  ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐ์‹ธ๋„ ๋ฉ๋‹ˆ๋‹ค.

<body>
  <div class="top">top!</div>
  <div class="bnf">
    <div class="bottom">bottom!!</div>
  </div>
</body>

๐Ÿ‘‡ ์ฐธ๊ณ ํ•œ ์‚ฌ์ดํŠธ

  1. MDN
  2. ์ œ๋กœ์ดˆ๋ธ”๋กœ๊ทธ

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