SASS හි @if නියෝගය

නිශ්චිත කොන්දේසි සපුරා ඇති විට පමණක් නිශ්චිත ශෛලීය යෙදිය යුතු නම්, අපි @if නියෝගය භාවිතා කරමු, එය false සහ null හැර වෙනත් ඕනෑම අගයක් ආපසු ලබා දෙයි:

පහත උදාහරණය සලකා බලමු:

styles.scss#main-button {
  @if 2 - 1 == 1 {
    color: green;
  }
  @if (2+3) < 3 {
    color: orange;
  }
  @if null {
    color: red;
  }
}

සංකලනයේ ප්‍රතිඵලය:

styles.css#main-button {
  color: green; 
}

@if ට පසු කොන්දේසිය පැවරීමේදී බහු @else if ප්‍රකාශන සහ එක් @else ප්‍රකාශනයක් භාවිතා කළ හැකිය.

styles.css$var: 20px;

a {
  @if $var == 10px {
    color: blue;
  } @else if $var == 25px {
    color: red;
  } @else if $var == 10px+10px {
    color: green;
  } @else {
    color: black;
  }
}

දැන් අපි styles.css ගොනුව දෙස බලමු:

styles.cssa {
  color: green;
}
Задание 1

පහත කේතයේ සංකලන ප්‍රතිඵලය කුමක් දැයි පැහැදිලි කරන්න:

styles.scss$size: 20px;
$font-size: 14px;

body {
  @if $size == $font-size {
    background-color: #7e7ed8;
  } @else if $size > $font-size {
    color: #f1bbbb;
  } @else {
    color: #000000;
  }
}
Задание 2

පහත කේතයේ සංකලන ප්‍රතිඵලය කුමක් දැයි පැහැදිලි කරන්න:

styles.scss$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;
  }
}