๐Ÿฆ_21.11.05 TIL

Boriยท2021๋…„ 11์›” 7์ผ
1
post-thumbnail

21๋…„ 11์›” 05์ผ

๐Ÿ“ CSS

๐Ÿ“Ž Box Model

box-sizing

  • box-sizing ์†์„ฑ์€ ๋ฐ•์Šค์˜ ํฌ๊ธฐ์— ๋Œ€ํ•œ ๊ธฐ์ค€์„ ์ •ํ•œ๋‹ค.
  • box-sizing: content-box์ผ ๋•Œ,
.box {
  box-sizing: content-box;
  width: 300px;
  height: 200px; 
  padding: 20px;
  border: 5px solid black;
  margin: 15px;
}
  • box-sizing: border-box์ผ ๋•Œ,
.box {
  box-sizing: border-box
  /* border๊นŒ์ง€ width์— ํฌํ•จ */
  width: 300px;
  height: 200px; 
  padding: 20px;
  border: 5px solid black;
  margin: 15px;
}

[์ถœ์ฒ˜: ์ œ์ฃผ์ฝ”๋”ฉ๋ฒ ์ด์Šค์บ ํ”„ - content-box, border-box ๋น„๊ต]

display

  • display ์†์„ฑ์€ ๋ฐ•์Šค์˜ ์„ฑ์งˆ์„ ์ง€์ •ํ•˜์—ฌ ์š”์†Œ๋ฅผ ์–ด๋–ป๊ฒŒ ๋ณด์—ฌ์ค„์ง€ ๊ฒฐ์ •

    inline์ค„๋ฐ”๊ฟˆ์ด ์ผ์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค.
    width, heigth, margin-top, margin-bottom ๊ฐ’ ์ง€์ • ๋ถˆ๊ฐ€
    block์ค„๋ฐ”๊ฟˆ์ด ์ผ์–ด๋‚œ๋‹ค.
    width, heigth, margin, padding ๋“ฑ ๋ชจ๋“  ๊ฐ’์„ ์ง€์ • ๊ฐ€๋Šฅ
    inline-blockinline ์ฒ˜๋Ÿผ ํ•œ ์ค„์— ์—ฌ๋Ÿฌ ์š”์†Œ๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ณ ,
    block ์ฒ˜๋Ÿผ width, heigth, margin, padding ๋“ฑ ๋ชจ๋“  ๊ฐ’์„ ์ง€์ • ๊ฐ€๋Šฅ
    contents์„ ํƒํ•œ ์š”์†Œ์˜ ๋‚ด์šฉ ์•ž์ด๋‚˜ ๋’ค์— ์ฝ˜ํ…์ธ ๋ฅผ ๋ถ™์ธ๋‹ค.
    flex๋ ˆ์ด์•„์›ƒ์„ ๋‹ค๋ฃฐ ๋•Œ ํ•˜๋‚˜์˜ ํ–‰ ๋˜๋Š” ์—ด์„ ๋‹ค๋ฃธ
    (1์ฐจ์› ๋ ˆ์ด์•„์›ƒ)
    grid2์ฐจ์› ๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ

[์ถœ์ฒ˜: ์œ„๋‹ˆ๋ธŒ]

[์ถœ์ฒ˜: ํŠœํ† ๋ฆฌ์–ผ๋กœ ๋ฐฐ์šฐ๋Š” HTML & CSS]

  • <img>ํƒœ๊ทธ๋Š” inline ์š”์†Œ์ธ๋ฐ ์–ด๋–ป๊ฒŒ width ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์„๊นŒ?
    => <img>๋Š” ์˜ˆ์™ธ์ ์œผ๋กœ width ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์˜ˆ) <div>์•ˆ๋…•ํ•˜์„ธ์š”</div>
    ์œ„์˜ ์˜ˆ์‹œ์—์„œ '์•ˆ๋…•ํ•˜์„ธ์š”'๋Š” ์š”์†Œ๊ฐ€ ์•„๋‹ˆ๋‹ค.
    => ๋ธŒ๋ผ์šฐ์ €๋Š” ์š”์†Œ๊ฐ€ ์•„๋‹Œ ๊ธ€์ž ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ inline ์š”์†Œ๋กœ ์ธ์‹ํ•œ๋‹ค.
  • ๋ ˆ์ด์•„์›ƒ์„ ์งค ๋•Œ ์ˆ˜ํ‰์ •๋ ฌ์€ ๋งค์šฐ ์ค‘์š”ํ•˜๋‹ค. ์ด ๋•Œ display: inline-block ์†์„ฑ์„ ์ด์šฉํ•˜๋ฉด ์ˆ˜ํ‰์ •๋ ฌ์„ ํ•  ์ˆ˜ ์žˆ์œผ๋‚˜ ์ด ๋ฐฉ๋ฒ•์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.
    => ๊ฐ ์š”์†Œ ์‚ฌ์ด์˜ ๋นˆ ์นธ/์ค„ ๋ฐ”๊ฟˆ์ด ์ŠคํŽ˜์ด์Šค๋กœ ์ธ์‹๋˜์–ด ์ž‘์€ ์—ฌ๋ฐฑ์„ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.
  • ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•
    • ๋นˆ ์นธ ์—†์ด ํ•œ ์ค„๋กœ ์ฝ”๋“œ ์ž‘์„ฑ
      <div></div><div></div>
    • ๋ถ€๋ชจ ์š”์†Œ์— font-siz: 0 ์ ์šฉ
      => ์ด ๋ฐฉ๋ฒ•์€ ํ•ด๋‹น ์š”์†Œ์— ๋‹ค์‹œ font-size๋ฅผ ์ ์šฉํ•ด์•ผ ํ•œ๋‹ค.

๐Ÿ“Ž Position

  • Position? ์›น ํŽ˜์ด์ง€์—์„œ HTML ํƒœ๊ทธ๋‚˜ id, class ๋ฐ•์Šค ๋“ฑ์˜ ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ์†์„ฑ. ํŽ˜์ด์ง€์˜ ๋ ˆ์ด์•„์›ƒ์„ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

position: static

  • ๊ธฐ๋ณธ๊ฐ’, html์— ์“ด ํƒœ๊ทธ ์ˆœ์œผ๋กœ ์œ„์น˜๊ฐ€ ์ง€์ •๋จ = normal flow์— ๋”ฐ๋ผ ๋ฐฐ์น˜
  • top, bottom, left, right, z-index๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ๊ตณ์ด ๊ธฐ์ž…ํ•  ํ•„์š”๋Š” ์—†์ง€๋งŒ, ๋ถ€๋ชจ ๊ฐ์ฒด์—์„œ ๋‹ค๋ฅธ position ์†์„ฑ ๊ฐ’์ด ์ง€์ •๋œ ๊ฒฝ์šฐ, ์ด๋ฅผ ๋ฌด์‹œํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

position: relative

  • ์ƒ๋Œ€์ ์ธ ์†์„ฑ์„ ๊ฐ€์ง
    => ๋ฌด์—‡์— ์ƒ๋Œ€์ ์ธ๊ฐ€? static, ์ฆ‰ ์›๋ž˜ ์ž์‹ ์ด ์žˆ์–ด์•ผ ํ•˜๋Š” ์œ„์น˜์— ์ƒ๋Œ€์ 
  • normal flow์— ๋”ฐ๋ผ ์œ„์น˜ํ•œ ๋‹ค์Œ, top, bottom, left, right ๊ฐ’์— ๋”ฐ๋ผ ๋ฐฐ์น˜

position: absolute

  • normal flow๋ฅผ ๋ฒ—์–ด๋‚˜๋Š” ์†์„ฑ
  • position:relative, absolute, fixed ์†์„ฑ์„ ๊ฐ€์ง„ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ถ€๋ชจ ์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ, top, bottom, left, right ๊ฐ’์— ๋”ฐ๋ผ ๋ฐฐ์น˜
  • ๋ถ€๋ชจ ์š”์†Œ์— position ๊ฐ’์ด ์ง€์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ, body๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜
  • position: absolute๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ?
    => ์›น ์ ‘๊ทผ์„ฑ์˜ ์ดˆ์  ์ด๋™(tabํ‚ค๋กœ ์ด๋™) : ์Šคํฌ๋ฆฐ๋ฆฌ๋” ์ด์šฉ์ž์™€ ํ‚ค๋ณด๋“œ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ์ฝ˜ํ…์ธ ์˜ ์ˆœ์„œ๊ฐ€ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์ œ๊ณต๋˜์–ด ์›น ํŽ˜์ด์ง€๋ฅผ ํƒ์ƒ‰ํ•˜๋Š”๋ฐ ์–ด๋ ค์›€์ด ์—†์–ด์•ผ ํ•œ๋‹ค.

์˜ˆ) ์ดˆ์ ์ด๋™์ด ์•„์ด๋”” ์ž…๋ ฅ โ†’ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ โ†’ ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ โ†’ ์•„์ด๋”” ์ €์žฅ ์ˆœ์„œ๋ผ๋ฉด '๋กœ๊ทธ์ธ ๋ฒ„ํŠผ'์„ ๋จผ์ € ํด๋ฆญํ•˜๊ธฐ ๋•Œ๋ฌธ์— '์•„์ด๋”” ์ €์žฅ์„ ๋ชปํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค.
๊ทธ๋Ÿฌ๋ฏ€๋กœ, ์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ โ†’ ์•„์ด๋”” ์ €์žฅ โ†’ ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ ์ˆœ์„œ์ธ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์ดˆ์ ์ด ์ด๋™ํ•ด์•ผ ํ•œ๋‹ค.
=> ๋…ผ๋ฆฌ์ ์ธ ์ˆœ์„œ๋กœ ๋งˆํฌ์—… ํ•œ ํ›„ position์„ ์ด์šฉํ•ด ์š”์†Œ๋ฅผ ๋ณด๊ธฐ ์ข‹๊ฒŒ ๋ฐฐ์น˜ํ•˜์—ฌ ์Šคํฌ๋ฆฐ๋ฆฌ๋” ์ด์šฉ์ž๋‚˜ ๋น„์ด์šฉ์ž ๋ชจ๋‘ ์›น ํŽ˜์ด์ง€๋ฅผ ํƒ์ƒ‰ํ•˜๋Š”๋ฐ ์–ด๋ ค์›€์ด ์—†์–ด์•ผ ํ•œ๋‹ค.

position: fixed

  • normal flow๋ฅผ ๋ฒ—์–ด๋‚˜๋Š” ์†์„ฑ
  • ํ˜„์žฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋ณด๊ณ ์žˆ๋Š” viewport๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์— ๋ถ™์€ ๊ฒƒ์ฒ˜๋Ÿผ ๊ทธ ์ž๋ฆฌ์— ์œ„์น˜
  • ์Šคํฌ๋กค์„ ์˜ฌ๋ฆฌ๊ฑฐ๋‚˜ ๋‚ด๋ ค๋„ position: fixed๊ฐ€ ์ง€์ •๋œ ์š”์†Œ๋Š” ๊ณ ์ •๋˜์–ด ์›€์ง์ด์ง€ ์•Š์Œ => ํŒ์—…์ฐฝ, ๋ฉ”๋‰ด, top ๋ฒ„ํŠผ ๋“ฑ
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>replit</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div class="box box1">box1</div>
    <div class="box box2">box2</div>
    <div class="box box3 relative_box">
      position: relative์ธ box3
      <div class="box absolte_box">relative ๋‚ด์— ์œ„์น˜ํ•œ absolute_box1</div>
      <div class="box">relative ๋‚ด์— ์œ„์น˜ํ•œ box2</div>
      <div class="box">relative ๋‚ด์— ์œ„์น˜ํ•œ box3</div>
    </div>
    <div class="box box4 absolte_box">body ๊ธฐ์ค€ absolute_box4</div>
    
    <div class="fixed_box">position: fixed</div>
    <script src="script.js"></script>
  </body>
</html>
      body {
        margin: 0;
        padding: 0;
        /* height: 1500px; */
      }
      
      .box {
        width: 150px;
        height:150px;
        background: rgba(0, 0, 0, 0.5);
      }

      .relative_box {
        position: relative;
        left: 50px;
        width: 400px;
        height: auto;
        background: tomato;
      }

      .absolte_box {
        position: absolute;
        right: 0;
        bottom: 50px;
      }

      .box1 {
        background-color: antiquewhite; 
      }

      .box2 {
        background-color: aqua; 
      }

      .box3 {
        background-color: aquamarine; 
      }

      .box4 {
        background-color:slategrey; 
      }

      .relative_box .box:nth-child(1) {
        background-color: tomato;
      }

      .relative_box .box:nth-child(2) {
        background-color: yellowgreen; 
      }

      .relative_box .box:nth-child(3) {
        background-color: violet; 
      }

      .fixed_box {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100px;
        height: 100px;
        background-color: rgba(0, 0, 0, 0.2);
      }

position: sticky

  • normal flow์— ๋”ฐ๋ผ ์œ„์น˜ํ•˜๋ฉฐ, ์Šคํฌ๋กค์ด ๋˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ธ”๋ก ๋ ˆ๋ฒจ์˜ ์ƒ์œ„ ์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜
  • ์ž์‹ ์˜ ์œ„์น˜ ์ž„๊ณ„์ (offset)์„ ๋„˜์„ ๋•Œ ๋ถ™์Œ
<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>position - sticky</title>
    <style>
      section {
        height: 1000px;
        border: 3px solid #000;
      }
      h2 {
        position: sticky;
        position: -webkit-sticky;
        top: 10px;
        background-color: cornflowerblue;
      }
    </style>
  </head>
  <body>
    <h1>sticky test</h1>
    <section>
      <h2>1. ์˜ค๋Š˜์˜ ์•„์นจ ๋ฉ”๋‰ด</h2>
      <ul>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
      </ul>
    </section>
    <section>
      <h2>1. ์˜ค๋Š˜์˜ ์ ์‹ฌ ๋ฉ”๋‰ด</h2>
      <ul>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
      </ul>
    </section>
    <section>
      <h2>1. ์˜ค๋Š˜์˜ ์ €๋… ๋ฉ”๋‰ด</h2>
      <ul>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
        <li>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta
          exercitationem odit similique non maiores eveniet quidem reiciendis
          aperiam quas fugiat? Minus ducimus culpa inventore sunt pariatur
          mollitia dolorum nemo reiciendis, fuga alias voluptatum facere modi
          officia debitis soluta error, odio nobis consequuntur. Atque placeat
          nulla sed sequi officiis architecto doloribus.
        </li>
      </ul>
    </section>
  </body>
</html>

z-index

  • position ์†์„ฑ์„ ๊ฐ€์ง„ ์š”์†Œ์— ๋Œ€ํ•ด z์ถ• ์ƒ์˜ ์œ„์น˜
  • z-index๊ฐ€ ์ง€์ •๋œ ๊ฒฝ์šฐ, ๋†’์€ ๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ง„ ๋ ˆ์ด์–ด๋Š” ๋‚ฎ์€ ๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ง„ ๋ ˆ์ด์–ด ์œ„์— ์œ„์น˜
  • z-index ์ ์šฉ / z-index๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์˜ ์Œ“์ž„

๐Ÿ“Ž Float

float ์˜๋ฏธ

  • '๋„์šฐ๋‹ค'๋ผ๋Š” ๋œป์„ ๊ฐ€์ง€๋ฉฐ, float ์ •๋ ฌ์€ ๋‹ค์–‘ํ•œ ๊ฐ์ฒด๋ฅผ ๋„์›Œ์„œ ์žฅ๋ ฌ์„ ํ•˜๋Š” ์†์„ฑ

float์˜ ๊ธฐ๋ณธ ๊ฐœ๋…

  • ์›๋ž˜ float์€ ์•„๋ž˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ๊ทธ๋ฆผ์„ ๋”ฐ๋ผ ํ๋ฅด๋Š” ํ…์ŠคํŠธ ๋ ˆ์ด์•„์›ƒ์„ ์›น์—์„œ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ํƒ„์ƒํ•œ ์†์„ฑ
  • ํ•˜์ง€๋งŒ ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ •๋ ฌ๋˜๋Š” ํŠน์„ฑ ๋•๋ถ„์— ํ˜„์žฌ๋Š” ๋ธ”๋ก ์†์„ฑ์„ ๊ฐ€์ง„ ๊ฐ์ฒด๋ฅผ ์ •๋ ฌํ•˜๋Š” ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค.
  • float: left/float: right์˜ ์„ฑ์งˆ์€ ๋ธ”๋ก ๋ฐ•์Šค์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ์˜ ๊ณต๊ฐ„๋งŒ ์ฐจ์ง€ํ•˜๊ณ  ๋‚˜๋จธ์ง€ ๋‚ด์šฉ์€ ๋ฐ•์Šค ์˜ค๋ฅธ์ชฝ/์™ผ์ชฝ์— ์œ„์น˜ํ•˜๋ฉฐ ์œ„์—์„œ ์•„๋ž˜์˜ ๋ฐฉํ–ฅ์ธ ํ๋ฆ„์„ ๊ฐ€์ง

[์ถœ์ฒ˜: Web Animation 1๋ถ€ css Animation - <img>์— float ์ ์šฉ]

float ์†์„ฑ์˜ ๋ฌธ์ œ์ 

  • ์ž์‹ ์š”์†Œ๋“ค์ด ๋ชจ๋‘ float ์†์„ฑ์„ ๊ฐ€์งˆ ๋•Œ ๋ถ€๋ชจ ์š”์†Œ๊ฐ€ ์ž์‹ ์š”์†Œ๋“ค์„ ์ธ์ง€ํ•˜์ง€ ๋ชปํ•œ๋‹ค.
    => ๋ถ€๋ชจ ์š”์†Œ๊ฐ€ height๊ฐ’์„ ์žƒ๋Š”๋‹ค.

[์ถœ์ฒ˜: Web Animation 1๋ถ€ css Animation - float ์ ์šฉ ์ „]

[์ถœ์ฒ˜: Web Animation 1๋ถ€ css Animation - float ์ ์šฉ ํ›„]

  • ๋ถ€๋ชจ ์š”์†Œ๊ฐ€ float๋œ ์ž์‹ ์š”์†Œ๋ฅผ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ• = float ํ•ด์ œ
    • ๋ถ€๋ชจ ์š”์†Œ์— overflow ์†์„ฑ ์ถ”๊ฐ€
      => overflow: hidden / overflow: scroll ๋“ฑ์˜ ํ•„์š”ํ•œ ์†์„ฑ์„ ์ถ”๊ฐ€
    • ๋ถ€๋ชจ ์š”์†Œ์— display: inline-block ์†์„ฑ ์ถ”๊ฐ€
    • ๋ถ€๋ชจ ์š”์†Œ์˜ ๋†’์ด ๊ฐ’์„ ์ง์ ‘ ์ง€์ •
      => ์ž์‹ ์š”์†Œ์— ์ง€์ •๋œ ๊ฐ’๋“ค์ด ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ ์ ˆํ•œ ๋ฐฉ๋ฒ•์€ ์•„๋‹ˆ๋‹ค.
    • clear ์†์„ฑ ์ ์šฉ
      => float์ด ์‚ฌ์šฉ๋œ ์š”์†Œ์˜ ๋ฐ”๋กœ ๋‹ค์Œ ํ˜•์ œ ์š”์†Œ์— float ์ •๋ ฌ์˜ ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ clear ์†์„ฑ์„ ์ ์šฉ
    • clear-fix : ๋ถ€๋ชจ ์š”์†Œ์— ::after ๊ฐ€์ƒ์š”์†Œ๋ฅผ ์ด์šฉํ•˜์—ฌ clear ์†์„ฑ ์ ์šฉ
      => ๋ณดํ†ต clear-fix ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ถ€๋ชจ ์š”์†Œ์— ์ ์šฉํ•˜์—ฌ ์‚ฌ์šฉ
      => display: block ์†์„ฑ์ด ์—†์œผ๋ฉด ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.
.clear::after {
  content: "";
  display: block;
  clear: both;
}
  • ๊ฐ€์ƒ ์š”์†Œ ๋งŒ๋“ค๊ธฐ
    • ::after: ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ์ž์‹ ์š”์†Œ๊ฐ€ ๋œ๋‹ค.
    • ::before: ๊ฐ€์žฅ ์ฒซ ๋ฒˆ์งธ ์ž์‹ ์š”์†Œ๊ฐ€ ๋œ๋‹ค.
  • ๊ฐ€์ƒ ์š”์†Œ๋ฅผ ์ด์šฉํ•˜๋Š” ์ด์œ ?
    • ์˜๋ฏธ์—†๋Š” html์„ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด
      => ํ•„์š”์—†๋Š” html์€ ์ตœ๋Œ€ํ•œ ์ž์ œํ•ด์•ผ ํ•œ๋‹ค.

float ์‹ค์Šต - ๋กœ๊ทธ์ธ ๋ ˆ์ด์•„์›ƒ ๋งŒ๋“ค๊ธฐ

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Login Layout</title>
    <style>
      @import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR&display=swap");

      @import "../reset.css";

      * {
        box-sizing: border-box;
      }

      body {
        color: #404040;
        font-family: "Noto Sans KR", sans-serif;
      }

      .login-container {
        width: 350px;
        height: 135px;
        margin: 20px;
        padding: 16px;
        border: 1px solid #dae1e6;
        background-color: #f7f9fa;
      }

      .login-container p {
        color: #808080;
        font-size: 14px;
      }

      .login-btn {
        width: 100%;
        margin: 15px 0 10px;
        padding: 15px 0;
        border: 1px solid #15c654;
        background-color: #19ce60;
        color: #fff;
        font-size: 13px;
      }

      .login-btn::before {
        content: "";
        display: inline-block;
        width: 60px;
        height: 12px;
        margin-right: 8px;
        background-image: url(images/title.png);
        background-size: 60px;
      }

      a {
        color: inherit;
        font-size: 13px;
        text-decoration: none;
      }

      a:hover {
        text-decoration: underline;
      }

      .find-id::before {
        content: "";
        display: inline-block;
        width: 10px;
        height: 14px;
        margin-right: 5px;
        background-image: url(images/lock.png);
        background-size: 10px;
      }

      .find-pw::before {
        content: "";
        display: inline-block;
        width: 3px;
        height: 3px;
        margin-right: 5px;
        border-radius: 50%;
        background-color: #d7dce0;
        vertical-align: middle;
      }

      .sign-up::before {
        content: "";
        display: inline-block;
        width: 11px;
        height: 11px;
        margin-right: 5px;
        background-image: url(images/user.png);
        background-size: 11px;
      }

      .sign-up {
        float: right;
      }

      footer::after {
        content: "";
        display: block;
        clear: both;
      }
    </style>
  </head>
  <body>
    <article class="login-container">
      <p>๋„ค์ด๋ฒ„๋ฅผ ๋” ์•ˆ์ „ํ•˜๊ณ  ํŽธ๋ฆฌํ•˜๊ฒŒ ์ด์šฉํ•˜์„ธ์š”</p>
      <!-- button ๋ณด๋‹ค a๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ ์ ˆ -->
      <button type="button" class="login-btn">๋กœ๊ทธ์ธ</button>
      <footer>
        <a href="#" class="find-id">์•„์ด๋””</a>
        <a href="#" class="find-pw">๋น„๋ฐ€๋ฒˆํ˜ธ์ฐพ๊ธฐ</a>
        <a href="#" class="sign-up">ํšŒ์›๊ฐ€์ž…</a>
      </footer>
    </article>
  </body>
</html>
  • <img>์— alt ๊ฐ’์ด ํ•„์š”ํ•˜์ง€ ์•Š์•„๋„ alt=""๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์ด์œ 
    => ์Šคํฌ๋ฆฐ๋ฆฌ๋”๊ฐ€ alt ๊ฐ’์ด ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ ์„ค๋ช…์ด ํ•„์š”์—†๋Š” ์ด๋ฏธ์ง€๋กœ ์ธ์‹ํ•˜์ž๋ฏผ alt ์†์„ฑ ์ž์ฒด๊ฐ€ ์—†์œผ๋ฉด src์„ ๊ธ€์ž ํ•˜๋‚˜ํ•˜๋‚˜ ์ฝ๋Š”๋‹ค.

  • vertical-align ์†์„ฑ
    => inline์š”์†Œ์—๋งŒ ์ ์šฉ์ด ๊ฐ€๋Šฅ
    => vertical-align: middle์€ ๋ผ์ธ์˜ ์ค‘์‹ฌ์ด ์•„๋‹ˆ๋‹ค. ์ฐธ๊ณ  ๋งํฌ

๐Ÿ“Ž Flex

  • flex? ์ฝ˜ํ…์ธ ๋ฅผ ์ •๋ ฌํ•˜๊ฑฐ๋‚˜ ๊ณต๊ฐ„์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋Š” CSS ์†์„ฑ์˜ ์ง‘ํ•ฉ

๊ธฐ๋ณธ ์†์„ฑ ์ •๋ณด

  • ๋ถ€๋ชจ ์š”์†Œ์ธ div.container๋ฅผ ํ†ตํ•ด ์ž์‹์š”์†Œ์ธ div.item์„ ์ปจํŠธ๋กค
    ์ด๋•Œ, ๋ถ€๋ชจ ์š”์†Œ๋ฅผ flex-container, ์˜ํ–ฅ์„ ๋ฐ›๋Š” ์ž์‹ ์š”์†Œ๋ฅผ flex-item์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
    => flex๋Š” ์ž์‹ ์˜ ์ง๊ณ„ ์ž์‹์—๊ฒŒ๋งŒ ์˜ํ–ฅ์„ ์ค€๋‹ค.
  <div class="container">
    <div class="item">box1</div>
    <div class="item">box2</div>
    <div class="item">box3</div>
  </div>  
  • ๋ธ”๋ก ๋ ˆ๋ฒจ ์š”์†Œ์˜ ์„ฑ์งˆ์„ ๊ฐ€์ง€๋Š” ์ƒˆ๋กœ์šด display ์†์„ฑ
  .container {
	display: flex;
	/* display: inline-flex; */
  }    

flex-item์€ ๊ธฐ๋ณธ์ ์œผ๋กœ Axis๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ

  • ๊ธฐ๋ณธ ๋ฐฉํ–ฅ : ์™ผ์ชฝ โ†’ ์˜ค๋ฅธ์ชฝ
  • axis์™€ ์ง์„ ์ด๋ฃจ๋Š” cross-axis๊ฐ€ ์กด์žฌ
    => axis๊ฐ€ row์ผ ๋•Œ, cross-axis๋Š” colum
    => axis๊ฐ€ colum์ผ ๋•Œ, cross-axis๋Š” row

flex-direction

  • ์ •๋ ฌ ๋ฐฉํ–ฅ์„ ๊ฒฐ์ •
flex-direction: rowflex-direction: row-reverse
flex-direction: columnflex-direction: column-reverse

justify-content

  • ๋ฉ”์ธ์ถ• ๋ฑกํ–ฅ ์ •๋ ฌ
  .container {
    display: flex;
    /* justify-content: flex-start; */
    /* justify-content: flex-end; */
    /* justify-content: center; */
    /* justify-content: space-between; */
    /* justify-content: space-around; */
    /* justify-content: space-evenly; */
  }
flex-start๊ธฐ๋ณธ๊ฐ’, ์•„์ดํ…œ์„ ์‹œ์ž‘์ ์„ ์ •๋ ฌ
flex-end์•„์ดํ…œ์„ ๋์ ์„ ์ •๋ ฌ
center์•„์ดํ…œ์„ ๊ฐ€์šด๋ฐ๋กœ ์ •๋ ฌ
space-between์•„์ดํ…œ๋“ค์˜ โ€œ์‚ฌ์ด(between)โ€์— ๊ท ์ผํ•œ ๊ฐ„๊ฒฉ
์ปจํ…Œ์ด๋„ˆ ์–‘ ๋์— ์—ฌ๋ฐฑ ์—†์ด ์ •๋ ฌ
space-around์•„์ดํ…œ๋“ค์˜ โ€œ๋‘˜๋ ˆ(around)โ€์— ๊ท ์ผํ•œ ๊ฐ„๊ฒฉ
์•„์ดํ…œ์˜ ์–‘์ชฝ ์—ฌ๋ฐฑ์„ ํฌํ•จํ•˜์—ฌ ์ •๋ ฌ
space-evenly์•„์ดํ…œ๋“ค์˜ ์‚ฌ์ด์™€ ์ปจํ…Œ์ด๋„ˆ ์–‘ ๋์— ๊ท ์ผํ•œ ๊ฐ„๊ฒฉ

๐Ÿ ์ œ 1ํšŒ ์ž์‹ ๋งŒ์˜ ์บ๋ฆญํ„ฐ ๊ทธ๋ฆฌ๊ธฐ ๊ฒฝ์ง„๋Œ€ํšŒ ๊ฒฐ๊ณผ


๋งˆ๋ฌด๋ฆฌ

  • float, position์„ ๋” ๊นŠ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์–ด๋ฌผ์ฉก ์•Œ๊ณ  ์žˆ๋˜ ๋ถ€๋ถ„๋“ค์ด ๋ช…ํ™•ํ•ด์ง„๋‹ค.
  • ํ•œ ๋ฒˆ ๊ณต๋ถ€ํ•œ ๊ฒƒ์€ ๊ณต๋ถ€ํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค.๋ผ๋Š” ๋ง์ด ์™€๋‹ฟ์•˜๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ™์€ ๋‚ด์šฉ์ด๋”๋ผ๋„ ์—ฌ๋Ÿฌ ์„ ์ƒ๋‹˜์˜ ๊ฐ•์˜๋ฅผ ํ†ตํ•ด ์ตํžˆ๋ฉด ์ดํ•ด๋„๊ฐ€ ๋†’์•„์ง„๋‹ค๋Š” ๋ถ€๋ถ„๋„ ๊ณต๊ฐ์ด ๋˜์—ˆ๋‹ค.
  • ๋™๋„ค ์‚ฌ๋žŒ๋“ค! ์ € ์บ๋ฆญํ„ฐ ๊ทธ๋ฆฌ๊ธฐ ์ƒ์žฅ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค์•„์•„!!! (์ฉŒ๋ ์ฉŒ๋ ) ์—ด์‹ฌํžˆ ํ•˜๊ธธ ์ž˜ํ–ˆ๋‹ค. ํžˆํžˆ๐Ÿ˜†
  • ์ฒ˜์Œ ์ž‘์„ฑํ–ˆ๋˜ TIL์„ ๋‹ค์‹œ ๋ดค๋‹ค. ๊ทธ๋•Œ๋Š” ๋‚˜๋ฆ„ ๋‚˜์˜์ง€ ์•Š๊ฒŒ ์ž‘์„ฑํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ์ง€๊ธˆ๋ณด๋‹ˆ ๋‚ด์šฉ์ด ๋ถ€์‹คํ•ด๋ณด์ธ๋‹ค. ํ‹ˆํ‹ˆํžˆ ์ˆ˜์ •ํ•ด์•ผ๊ฒ ๋‹ค.

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