Udhëzrreshti @if në SASS
Nëse kemi nevojë që stile të caktuara
të aplikohen vetëm nëse plotësohen
kushte specifike, atëherë përdorim
udhëzrreshtin @if, i cili kthen
çdo vlerë, përveç false dhe null:
Le të shqyrtojmë shembullin e mëposhtëm:
#main-button {
@if 2 - 1 == 1 {
color: green;
}
@if (2+3) < 3 {
color: orange;
}
@if null {
color: red;
}
}
Rezultati i kompilimit:
#main-button {
color: green;
}
Gjithashtu, pas vendosjes së kushtit pas @if
mund të përdoren disa @else if
dhe një shprehje @else.
$var: 20px;
a {
@if $var == 10px {
color: blue;
} @else if $var == 25px {
color: red;
} @else if $var == 10px+10px {
color: green;
} @else {
color: black;
}
}
Tani le të shohim skedarin styles.css:
a {
color: green;
}
Tregoni, çfarë do të jetë rezultati i kompilimit të kodit në vijim:
$size: 20px;
$font-size: 14px;
body {
@if $size == $font-size {
background-color: #7e7ed8;
} @else if $size > $font-size {
color: #f1bbbb;
} @else {
color: #000000;
}
}
Tregoni, çfarë do të jetë rezultati i kompilimit të kodit në vijim:
$size: 20px;
$font-size: 14px;
.active {
@if $size < $font-size {
color: red;
} @else if $size > $font-size {
color: green;
} @else {
color: #000000;
}
}
.not-active {
@if $size == $font-size {
display:block ;
} @else {
display: none;
}
}