SASS'ta @at-root Direktifi

@at-root direktifi, kuralları üst seçiciden çıkarıp dosyanın köküne yerleştirmek için tasarlanmıştır.

Birinci iç içe geçme seviyesindeki seçicilerle aşağıdaki örneği inceleyelim:

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

Derleme sonucunda aşağıdaki kod elde edilir:

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

Şimdi de @at-root direktifinin birden fazla seçici ile çalışmasına bakalım:

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

Derlemeden sonra kod şu şekilde görünür:

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

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

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

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

Aşağıdaki kodun derleme sonucunun nasıl olacağını açıklayın:

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