scss Mixins Sass

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss Mixins Sass相关的知识,希望对你有一定的参考价值。

/* Margin bottom ranges .mb-1, .mb-2, ... */

$iphone5: 'screen and (device-aspect-ratio: 40/71)';

@mixin mb($number) {
  margin-bottom: calc(#{$number}vh * 2);

  @media #{$iphone5} {
    margin-bottom: calc(#{$number}vh * 1.5);
  }
}

@for $numbers from 1 through 7 {
  @each $number in $numbers {
    .mb-#{$number} {
      @include mb($number);
    }
  }
}

/* Another way */
@mixin mb {
  @for $numbers from 1 through 7 {
    @each $number in $numbers {
      &-#{$number} {
        margin-bottom: calc(#{$number}vh * 1.5);

        @media #{$iphone5} {
          margin-bottom: calc(#{$number}vh * 0.7);
        }
      }
    }
  }
}

.mb {
  @include mb();
}

以上是关于scss Mixins Sass的主要内容,如果未能解决你的问题,请参考以下文章

scss CSS Flexbox - Sass Mixins

scss 用于媒体查询的Sass mixins

scss Mixins Sass

scss 因为只有sass mixins

scss CSS Flexbox - Sass Mixins

scss 设置功能mixins sass