λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
[개발] Practice/HTML CSS

[HTML/CSS] SCSS 둜 Alert λ°•μŠ€ λ§Œλ“€κΈ°

by Connecting-the-dots 2022. 3. 1.
728x90
λ°˜μ‘ν˜•

πŸ’‘ μ‹€μŠ΅ 포인트!

  • % λ₯Ό μ΄μš©ν•œ μž„μ‹œν΄λž˜μŠ€ 생성 및 @extend λ₯Ό ν™œμš©ν•˜μ—¬ 이미 μžˆλŠ” 클래슀λ₯Ό 상속, ν™•μž₯ν•΄λ³΄μ•˜λ‹€.
  • 참고둜 % λŠ” . λŒ€μ‹  μ‚¬μš© κ°€λŠ₯ν•œ μž„μ‹œν΄λž˜μŠ€λ‘œ CSS νŒŒμΌμ—μ„œ 클래슀둜 μ»΄νŒŒμΌν•˜κ³  싢지 μ•Šμ„ λ•Œ μ‚¬μš©ν•˜λ©°, κ·Έλž˜μ„œ μ‹€μ œλ‘œ μ»΄νŒŒμΌλ˜μ—ˆμ„ λ•Œ @extend 받은 클래슀λͺ…λ“€λ‘œ λͺ¨μ•„μ„œ ν‘œκΈ°λ¨

πŸ’œ Alert λ°•μŠ€ λ ˆμ΄μ•„μ›ƒ

πŸ’œ HTML

    <div class="alert-box-green">
        <p>Alert Number 1!</p>
    </div>
    <div class="alert-box-blue">
        <p>Alert Number 2!</p>
    </div>
    <div class="alert-box-yellow">
        <p>Alert Number 3!</p>
    </div>

πŸ’œ SCSS

%alert-box {
  padding: 15px;
  width: 90%;
  margin: auto;
  margin-top: 15px;
  font-weight: bold;
  border-radius: 5px;
}

.alert-box-green {
  @extend %alert-box;
  border: 1.5px solid rgb(99, 236, 99);
  background: lightgreen;
  color: darkgreen;
}

.alert-box-blue {
  @extend %alert-box;
  border: 1.5px solid rgb(114, 201, 230);
  background: lightblue;
  color: darkblue;
}

.alert-box-yellow {
  @extend %alert-box;
  border: 1.5px solid rgb(241, 241, 137);
  background: lightgoldenrodyellow;
  color: darkgoldenrod;
}
  •  %λ₯Ό 클래슀λͺ… μ•žμ— 뢙이면 μž„μ‹œν΄λž˜μŠ€κ°€ μƒμ„±λœλ‹€. (ν΄λž˜μŠ€μž„μ„ λœ»ν•˜λŠ” λ§ˆμΉ¨ν‘œλ₯Ό 뢙이지 μ•ŠλŠ” 게 포인트!)
  • ν˜„μž¬ λ§Œλ“€κ³ μž ν•˜λŠ” λ°•μŠ€λŠ” 배경색, ν°νŠΈμƒ‰, ν…Œλ‘λ¦¬λ§Œ λ‹€λ₯΄λ―€λ‘œ 그것을 μ œμ™Έν•œ 곡톡적인 속성듀은 μž„μ‹œν΄λž˜μŠ€μ— 담아두고 @extend λ₯Ό μ‚¬μš©ν•˜μ—¬ μƒμ†λ°›λŠ”λ‹€.
  • 그러면 μ€‘λ³΅λœ μ½”λ“œλ₯Ό 쀄이고, λ² μ΄μŠ€κ°€ λ˜λŠ” 뢀뢄은 μž„μ‹œν΄λž˜μŠ€μ—μ„œ μˆ˜μ •ν•˜λ©΄ λœλ‹€.

πŸ’œ μ»΄νŒŒμΌν•˜μ—¬ CSS 둜 λ³€ν™˜

.alert-box-yellow, .alert-box-blue, .alert-box-green {
  padding: 15px;
  width: 90%;
  margin: auto;
  margin-top: 15px;
  font-weight: bold;
  border-radius: 5px;
}

.alert-box-green {
  border: 1.5px solid #63ec63;
  background: lightgreen;
  color: darkgreen;
}

.alert-box-blue {
  border: 1.5px solid #72c9e6;
  background: lightblue;
  color: darkblue;
}

.alert-box-yellow {
  border: 1.5px solid #f1f189;
  background: lightgoldenrodyellow;
  color: darkgoldenrod;
}/*# sourceMappingURL=alertbox.css.map */
728x90
λ°˜μ‘ν˜•