首页 > 解决方案 > 这个使用 mixin 函数的 SASS 代码是否过于冗长?

问题描述

我觉得这个mixin的代码太冗长了,请帮忙。
请随时通过有关 mixins 的任何建议。

  @mixin bold { font-weight: bold; }

  @mixin normal { font-weight: normal; }

  @mixin font($bold, $normal) {
    @if ($bold) {
      @include bold

    } @else {
      font-weight: normal;
    }
  }

  h1 { @include font(false, false) }
  h2 { @include font(true, true) }

标签: sass

解决方案


你可以简化它:

$bold: 700;
$normal: 400;

h1 {
    font-weight: $bold;
}
h2 {
    font-weight: $normal;
}

推荐阅读