SCSS 中的 Mixin(一个类在另一个类中的属性)

问题描述 投票:0回答:2

在 LESS 中我可以写这样的东西:

.foo {
    color: red;
}

.boo {
    .foo();
    background: blue;
}

.foo
类的属性“包含”到
.boo
类中。

在 SCSS 中获得类似行为的最简单、最干净的方法是什么?

sass less scss-mixins
2个回答
1
投票

这样尝试怎么样,

mixins.scss

@mixin flex($x: center, $y: center) {
    display: flex;
    align-items: $x;
    justify-content: $y;
}

自定义.scss

.classname {
    @include flex(flex-start, space-between);
    color: red;
}

使用@include


0
投票

您可以使用占位符,如下所示:

%foo {
  color: red;
}

.background {
  @extend %foo;
  background: blue;
}
© www.soinside.com 2019 - 2024. All rights reserved.