01.CSS 기초 - block-level & inline-level

ID짱재·2021λ…„ 3μ›” 16일
0

CSS

λͺ©λ‘ 보기
5/15
post-thumbnail

🌈 block-level & inline-level

πŸ”₯ block-level & inline-level λž€?

πŸ”₯ display 속성

πŸ”₯ visibility 속성

πŸ”₯ inline-block νŠΉμ§•


1. block-level & inline-level λž€?

  • λͺ¨λ“  νƒœκ·Έλ“€μ€ default κ°’μœΌλ‘œ block-level μš”μ†Œμ™€ inline-level μš”μ†Œμ˜ νŠΉμ„±μ„ 가짐
  • inline-level μš”μ†Œλ“€μ€ 각 μš”μ†Œμ˜ 컨텐츠듀이 μ˜†μœΌλ‘œ 연이어 λ‚˜νƒ€μ§€λ§Œ, block-level μš”μ†ŒλŠ” 기본적으둜 box처럼 μ˜†μ— 아무것도 λ‘˜ 수 μ—†κΈ° λ•Œλ¬Έμ— ν•œ 라인의 λ„ˆλΉ„λ₯Ό λͺ¨λ‘ μ°¨μ§€ν•˜κ²Œ 됨

1) block-level의 νŠΉμ„±

  • 항상 μƒˆλ‘œμš΄ 라인에 λ‹€μŒ νƒœκ·Έλ₯Ό μœ„μΉ˜μ‹œν‚΄
  • ν™”λ©΄μ˜ λ„ˆλΉ„ 전체λ₯Ό 차지
  • width, height, margin, padding 속성 μ„€μ • κ°€λŠ₯
  • block μš”μ†Œ μ•ˆμ— inline μš”μ†Œ 포함 κ°€λŠ₯
  • defaulκ°’μœΌλ‘œ block-level νŠΉμ„±μ„ 가진 νƒœκ·Έ : div / h1~h6 / p, ol, ul, li, hr, table, form λ“±

2) inline-level의 νŠΉμ„±

  • 같은 라인에 λ‹€λ₯Έ μš”μ†Œμ™€ 연이어 μœ„μΉ˜ κ°€λŠ₯
  • content λ„ˆλΉ„λ§ŒνΌ κ°€λ‘œν­μ„ 가짐
  • width, height, margin, padding λ“±μ˜ 속성 μ„€μ • λΆˆκ°€λŠ₯
  • μƒν•˜ 여백은 line-height둜 지정 κ°€λŠ₯
  • inline νŠΉμ„±μ„ 가진 νƒœκ·Έ μ•ˆμ— block νŠΉμ„±μ„ 가진 μš”μ†Œ 포함 λΆˆκ°€λŠ₯
  • defaulκ°’μœΌλ‘œ inline-level νŠΉμ„±μ„ 가진 νƒœκ·Έ : span / a / strong / img / br / input / select / textarea / button λ“±

✍🏻 html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <style>
      .spantag {
        background-color: tomato;
      }
      .divtag {
        background-color: aquamarine;
      }
    </style>
  </head>
  <body>
    <h2>div νƒœκ·Έ 속에 span νƒœκ·Έ</h2>
    <div class="spantag">
      이것 뢀뢄은 div νƒœκ·Έλ‘œ 묢인 ν•œ λ¬Έμž₯μž…λ‹ˆλ‹€.
      <span>"이 λΆ€λΆ„μ€λ§Œ span νƒœκ·Έλ‘œ 감싸져 μžˆμŠ΅λ‹ˆλ‹€."</span> span은 inline-block μš”μ†Œμ΄κΈ° λ•Œλ¬Έμ— 쀄 λ°”κΏˆμ΄ λ˜μ§€
      μ•ŠμŠ΅λ‹ˆλ‹€.
    </div>
    <h2>span νƒœκ·Έ 속에 div νƒœκ·Έ</h2>
    <span class="divtag">
      이것 뢀뢄은 span νƒœκ·Έλ‘œ 묢인 λ¬Έμž₯μž…λ‹ˆλ‹€.
      <div>"이 λΆ€λΆ„λ§Œ divνƒœκ·Έλ‘œ 감싸져 μžˆμŠ΅λ‹ˆλ‹€."</div>
      divλŠ” block-level μš”μ†Œμ΄κΈ° λ•Œλ¬Έμ— λͺ¨λ“  μ˜μ—­μ„ μ°¨μ§€ν•˜μ—¬ μ€„λ°”κΏˆμ΄ λ©λ‹ˆλ‹€.
    </span>
  </body>
</html>


2. display 속성

  • πŸ” selector { display : block } : block νŠΉμ„±μ„ κ°€μ§€λŠ” μš”μ†Œλ‘œ 지정
  • πŸ” selector { display : inline } : inline νŠΉμ„±μ„ κ°€μ§€λŠ” μš”μ†Œλ‘œ 지정
  • πŸ” selector { display : inline-block} : inline-block νŠΉμ„±μ„ κ°€μ§€λŠ” μš”μ†Œλ‘œ 지정
  • πŸ” selector { display : none } : μš”μ†Œλ₯Ό 화면에 ν‘œμ‹œν•˜μ§€ μ•Šμ„ λΏλ”λŸ¬ μš”μ†Œκ°€ μ°¨μ§€ν•˜λŠ” μ˜μ—­(곡간)도 사라짐

3. visibility 속성

  • πŸ” selector { visibility : visible } : ν•΄λ‹Ή μš”μ†Œλ₯Ό 화면에 ν‘œμ‹œ(default κ°’)
  • πŸ” selector { visibility : hidden } : ν•΄λ‹Ή μš”μ†Œλ₯Ό 화면에 ν‘œμ‹œν•˜μ§€ μ•ŠμœΌλ‚˜, μ°¨μ§€ν•˜λŠ” 곡간은 남겨둠
  • πŸ” selector { visibility : collapse} : table μš”μ†Œμ— μ‚¬μš©ν•˜μ—¬ 행이라 열을 보이지 μ•Šκ²Œ 함

✍🏻 html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <style>
      body {
        display: flex;
      }
      div {
        width: 300px;
      }
      span {
        background-color: tomato;
      }
      strong {
        background-color: aquamarine;
      }
      .display_none {
        display: none;
      }
      .visibility_hidden {
        visibility: hidden;
      }
    </style>
  </head>
  <body>
    <div>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
      <strong>Can you see me? Can you see me? Can you see me? Can you see me?</strong>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
    </div>
    <div>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
      <strong class="display_none">Can you see me? Can you see me? Can you see me? Can you see me?</strong>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
    </div>
    <div>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
      <strong class="visibility_hidden">Can you see me? Can you see me? Can you see me? Can you see me?</strong>
      <span>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nesciunt facere iusto provident corporis? Nulla, exrerum voluptatem fuga rem saepe, quis, voluptatibus nihil consequuntur tempore repellat accusantium ab? Totam,tempora.</span>
    </div>
  </body>
</html>


4. inline-block νŠΉμ§•

  • block-level μš”μ†Œμ— μ†μ„±κ°’μœΌλ‘œ "display:inline"을 μ£Όλ©΄ inline-level μš”μ†Œμ²˜λŸΌ μ˜†μœΌλ‘œ μš”μ†Œλ“€μ„ 연이어 μ‚¬μš©ν•  수 μžˆμœΌλ‚˜, μ½˜ν…μΈ  λ‚΄μš©μ„ 넣어주지 μ•ŠμœΌλ©΄ ν™”λ©΄μ—μ„œ λ‚˜νƒ€λ‚˜μ§€ μ•ŠμŒ
  • 이럴 λ•Œ, ν•΄κ²° λ°©λ²•μœΌλ‘œ "display:inline"이 μ•„λ‹Œ "display:inline-block"λ₯Ό μ£Όλ©΄ inlineκ³Ό block의 속성을 λͺ¨λ‘ κ°€μ§€κ²Œ 됨
  • λ‹€λ§Œ, 이 λ°©μ‹μœΌλ‘œ block-level μš”μ†Œλ“€μ„ μ˜†μœΌλ‘œ 이어 λ°°μΉ˜ν–ˆμ„ λ•Œ, 개발자 λ„κ΅¬μ—μ„œ μˆ˜μΉ˜μƒ ν‘œμ‹œλ˜μ§€ μ•ŠλŠ” μš”μ†Œ κ°„ 여백이 λ°œμƒν•˜κΈ° λ•Œλ¬Έμ— μš”μ†Œλ“€μ„ μ •λ ¬ν•˜κΈ° μœ„ν•΄ μˆ˜μž‘μ—…μ΄ ν•„μš”
  • λΏλ§Œμ•„λ‹ˆλΌ, 이 μš”μ†Œλ“€(block-level μš”μ†Œ)이 화면에 크기에 따라 λ‹€λ₯΄κ²Œ μ •λ ¬λ˜λŠ” 문제 λ°œμƒν•˜μ—¬ μš”μ†Œλ“€μ„ ν†΅μ œν•˜κΈ° 어렀움
  • 이런 κΈ°λŒ€ν•˜μ§€ μ•Šμ€ κ²°κ³Όλ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ λ‚˜νƒ€λ‚œ κ°œλ…μ΄ display:"flex" μ†μ„±μž„

✍🏻 html

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    body {
      margin: 20px;
    }
    div {
      display: inline-block;
      width: 300px;
      height: 300px;
      background-color: teal;
      margin-right: 10.01;
    }
  </style>
</head>
<body>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</body>
</html>

profile
Keep Going, Keep Coding!

0개의 λŒ“κΈ€