【发布时间】:2020-05-13 00:22:18
【问题描述】:
我是使用 SASS 的新手,我发现了很多关于如何更改主按钮颜色的帖子,这很容易,但我也想更改边框和悬停。我能想到的唯一方法是添加一个我称之为“基本”的额外类。这是我的代码:
SCSS
$btn-bg: $bright-pink;
@mixin button-variant($color, $background, $border) {
color: #fff;
background-color: $btn-bg;
border: 3px solid $btn-bg;
&:hover {
color: $btn-bg;
background-color: $transparent;
border: 3px solid $btn-bg;
}
}
.btn-primary.basic { @include button-variant
(#fff,
$btn-basic,
3px solid $btn-bg);
}
HTML
<button type="button" class="btn btn-primary basic">Primary text</button>
有没有更好的方法来做到这一点?我可以在不添加额外类的情况下覆盖主按钮吗?
【问题讨论】:
-
“但我也希望更改边框和悬停” 两个副本都显示了这一点。查看按钮变体 mixin 的第二个和第三个参数。
-
我发现了我的问题。在 custom.scss 中的自定义覆盖文件之后,我正在加载 bootstrap.scss 文件,因此没有任何内容被覆盖。答案在这里stackoverflow.com/questions/43565650/…
标签: sass bootstrap-4 scss-mixins