【问题标题】:Overriding bootstrap 4 primary button styling with scss [duplicate]用scss覆盖bootstrap 4主按钮样式[重复]
【发布时间】: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


【解决方案1】:

要创建按钮的新变体,请使用以下 SASS。

然后在元素上使用“btn-primary basic” ass 类。

$btn-background: #39a4d2;
$btn-border: #56a1c5;
$btn-color: #fff;

@mixin button-variant($background, $border, $color) {
    background-color: $btn-background;
    border: 2px solid $btn-border;
    color: #fff;

    &:hover {
        border: 2px solid $btn-background;
        color: $btn-color;
    }
}

.btn-primary {
    &.basic {
        @include button-variant($btn-background, $btn-border, $btn-color);
    }
}

【讨论】:

  • 这对 bootstrap 5 也适用吗?
猜你喜欢
  • 1970-01-01
  • 2020-02-02
  • 2023-03-16
  • 2019-01-20
  • 2019-03-27
  • 2020-12-17
  • 2018-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多