scss自定义mixin覆盖更改值不会替换,而是添加

问题描述

我想将边框半径值 0 覆盖为 4px

不替换,而是添加。我在做什么错了?

@import:theme.scss:

.uk-button {
    border-radius: 0;
    @if(mixin-exists(hook-button)) { @include hook-button(); }
}

custom.scss:

// Custom mixin overwrites
// that's correct?
@mixin hook-button() {
    border-radius: 4px;
}

意外结果:

.uk-button {
    border-radius: 0; 
    border-radius: 4px;
}

预期结果:

.uk-button {
    border-radius: 4px;
}

解决方法

@include,如其所说,仅添加/包括特定规则,而不替换它们。

主题SCSS应该如下所示:

.uk-button {
    @if(mixin-exists(hook-button)) { @include hook-button(); }
    @else { border-radius: 0; }
}