Sass中带参数混合

SASS 中带参数的混合和 LESS 中也一样

  • 不带默认值形参
@mixin whc($w, $h, $c) {
  width: $w;
  height: $h;
  background: $c;
}

.box1 {
  @include whc(300px, 300px, red);
}

.box2 {
  @include whc(200px, 200px, blue);
}

image-20210814232951800

  • 带默认值形参
@mixin whc($w: 100px, $h: 100px, $c: #000) {
  width: $w;
  height: $h;
  background: $c;
}

.box1 {
  @include whc();
}

.box2 {
  @include whc(200px, 200px, blue);
}

image-20210814233107306

  • 给指定参数赋值
@mixin whc($w: 100px, $h: 100px, $c: #000) {
  width: $w;
  height: $h;
  background: $c;
}

.box1 {
  @include whc(300px, 300px, red);
}

.box2 {
  @include whc($c: blue);
}

image-20210814233533093

posted @ 2021-08-14 23:37  BNTang  阅读(107)  评论(0)    收藏  举报