๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๊ฐœ๋ฐœ] Practice/HTML CSS

[HTML/CSS] SCSS ๋กœ row, col ๋งŒ๋“ค๊ธฐ

by Connecting-the-dots 2022. 3. 1.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ์‹ค์Šต ํฌ์ธํŠธ!

  • Bootstrap ์—๋Š” row, col ์ด๋ผ๋Š” ๊ต‰์žฅํžˆ Grid ํ˜•ํƒœ๋กœ ๋งŒ๋“ค๊ธฐ ํŽธํ•œ  class ๊ฐ€ ์žˆ๋Š”๋ฐ ์˜ค๋Š˜์€ ๊ทธ๊ฒƒ์„ ์ง์ ‘ ๋งŒ๋“ค์–ด๋ณด์•˜๋‹ค.
  • ๊ทธ๋ฆฌ๊ณ  ํˆฌ๋ช…ํ•˜๋ฉด ์ œ๋Œ€๋กœ ๋ ˆ์ด์•„์›ƒ์ด ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€ ํ™•์ธ์ด ์–ด๋ ค์›Œ border ๊ณผ text ๋ฅผ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.
  • SCSS ์˜ @mixin ๊ณผ @include ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์—ˆ๋‹ค.
  • @mixin ๊ณผ @extend ๋Š” ์ƒ๋‹นํžˆ ์œ ์‚ฌํ•œ๋ฐ @mixin ์˜ ์žฅ์ ์ด๋ผ๋ฉด ๋‚ด๋ถ€์— ๋ฌถ์–ด๋‘” ์†์„ฑ๋“ค์— ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๐Ÿ’œ HTML

    <div class="row">
        <div class="col-6">col-6</div>
        <div class="col-6">col-6</div>
    </div>
    <div class="row">
        <div class="col-4">col-4</div>
        <div class="col-4">col-4</div>
        <div class="col-4">col-4</div>
    </div>

๐Ÿ’œ SCSS

  • @mixin ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ณ  width ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ํ•ด๋‹น๋ถ€๋ถ„์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์˜€๋‹ค.
  • ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ถ™์ธ ์ด๋ฆ„ ์•ž์— $(๋‹ฌ๋Ÿฌํ‘œ์‹œ)๋ฅผ ๋ถ™์—ฌ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
.row {
  @mixin col($width) {
    border: 1px solid lightgrey;
    float: left;
    padding: 15px;
    margin: 10px 0;
    text-align: center;
    width: $width;
  }

  .col-6 {
    @include col(50%);
  }

  .col-4 {
    @include col(33.33%);
  }
}

๐Ÿ’œ CSS

.row .col-6 {
  border: 1px solid lightgrey;
  float: left;
  padding: 15px;
  margin: 10px 0;
  text-align: center;
  width: 50%;
}
.row .col-4 {
  border: 1px solid lightgrey;
  float: left;
  padding: 15px;
  margin: 10px 0;
  text-align: center;
  width: 33.33%;
}/*# sourceMappingURL=row&col.css.map */
728x90
๋ฐ˜์‘ํ˜•