我想防止重复/覆盖CSS定义。 在我的示例中,我在mixins headlineTypo中定义了默认值。如果@include headlineTypo中的值为null,则默认情况下font-weight为700。 当我声明一个新的CSS类(标题中等)时,$ weight将设置默认值,所以我有:
.headline { font-size:12px ; font-weight: 700 }
.headline-medium { font-size:19px; font-weight: 700 }
@if ($weight != null) and (type-of($weight) == '700') {
font-weight: $weight;
} @else {
font-weight: 700; // Set default
}
@mixin headlineTypo($size: null, $weight: null) {
@if $size != null {
font-size: $size;
} @else {
font-size: 24px; // Set default
}
@if ($weight != null) and ($weight != 700) {
font-weight: $weight;
} @else {
font-weight: 700; // Set default
}
}
.headline {
@include headlineTypo(12px, null); // overwrite $size
&-medium {
@include headlineTypo(19px, null); // overwrite $size
}
}