SASS හි @at-root නියෝගය

@at-root නියෝගය සැලසුම් කර ඇත්තේ මව් තේරීමකින් නීති ප්‍රධාන ගොනුවට පිටතට ගැනීම සඳහා ය.

පහත උදාහරණය පළමු මට්ටමේ කට්ටල තේරීම් සමඟ සලකා බලමු:

style.scss.parent {
  background-color: #fdd;
  @at-root .child {
    border: 1px solid;
  }
}

සංකලනයේ ප්‍රතිඵලයක් වශයෙන් අපට පහත කේතය ලැබුණි:

styles.css.parent {
  background-color: #fdd;
}
.child {
  border: 1px solid;
}

දැන් අපි @at-root නියෝගයේ ක්‍රියාකාරිත්වය තේරීම් කිහිපයක් සමඟ නරඹමු:

style.scss.main-parent {
  background-color: #fdd;
  @at-root {
    .first-child {
      border: 1px solid;
    }
    .second-child {
      font-weight: bold;
    }  
  }
  .step-child {
    color: #232523;
  }
}

සංකලනයෙන් පසු කේතය පහත පරිදි පෙනේ:

styles.css.main-parent {
  background-color: #fdd; 
}

.first-child {
  border: 1px solid; 
}

.second-child {
  font-weight: bold; 
}

.main-parent .step-child {
  color: #232523; 
}
Задание 1

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

styles.scss.primary-button {
  background-color: #3272c7;
  @at-root {
    .block-button {
      color: #ff0000;
    }
    .content-button {
      color: #ccb42a;
    }
  }
  .warning-button {
    border: 2px solid #232523;
  }
}