본문 바로가기
: ) Web/웹 스터디

[Sass 실습2] extend, mixin 문법을 이용해 alert 박스 만들기

by miiinn 2023. 12. 13.

[결과 화면]

 

[HTML]

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UFT-8">
        <title>Document</title>
        <link href="hw2.css" rel="stylesheet">
    </head>

    <body>

        <div>
            <div class="alert-box-green"><p><strong>Well done!</strong> You successfully read this important alert message.</p></div>
            <div class="alert-box-blue"><p><strong>Heads up!</strong> This alert needs your attention, but it's not super important.</p></div>
            <div class="alert-box-yellow"><p><strong>Warning!</strong> Better check yourself, you're not looking too good.</p></div>
        </div>

    </body>
</html>

 

 

[SCSS]

// mixin, extend 이용

$초록 : #298F07;
$파랑 : #0067A3;
$노랑 : #FFD400;

%btn {
    padding: 5px;
    margin: 5px;
    border: 2px solid black;
    border-radius: 10px;
} 

@mixin 색깔($버튼색깔, $글씨색깔){
    background-color: $버튼색깔;
    color: $글씨색깔;
}

.alert-box-green {
    @extend %btn;
    @include 색깔($초록, #134204);
}

.alert-box-blue {
    @extend %btn;
    @include 색깔($파랑, #084b71);
}

.alert-box-yellow {
    @extend %btn;
    @include 색깔($노랑, #584a05);
}
// mixin, extend 이용

$초록 : #298F07;
$파랑 : #0067A3;
$노랑 : #FFD400;

%btn {
    padding: 5px;
    margin: 5px;
    border: 2px solid black;
    border-radius: 10px;
}

@mixin 색깔($버튼색깔, $글씨색깔){
    background-color: $버튼색깔;
    color: $글씨색깔;
}

.alert-box-green {
    @extend %btn;
    @include 색깔($초록, #134204);
}

.alert-box-blue {
    @extend %btn;
    @include 색깔($파랑, #084b71);
}

.alert-box-yellow {
    @extend %btn;
    @include 색깔($노랑, #584a05);
}