如何在Bootstrap 4和Sass中设置自定义按钮文本颜色?

时间:2018-05-07 22:26:29

标签: twitter-bootstrap sass bootstrap-4 scss-mixins

我想在Bootstrap 4中创建一个带有白色(#fff)文本颜色的新按钮样式。 Mixin button-variant根据背景颜色自动设置文本颜色。如何在不修改_buttons.scss

的情况下使用此mixin并同时设置颜色

custom.scss

.my_button {
  @include button-variant(HOW TO SET TEXT COLOR TO WHITE?);
}

_buttons.scss

@mixin button-variant($background, $border, $hover-background: darken($background, 7.5%), $hover-border: darken($border, 10%), $active-background: darken($background, 10%), $active-border: darken($border, 12.5%)) {
  color: color-yiq($background);
  @include gradient-bg($background);
  border-color: $border;
  @include box-shadow($btn-box-shadow);

  @include hover {
    color: color-yiq($hover-background);
    @include gradient-bg($hover-background);
    border-color: $hover-border;
  }

1 个答案:

答案 0 :(得分:6)

这类似于:How to create new set of color styles in Bootstrap 4 with sass

您需要使用@include作为自定义按钮,设置color:,然后传入相应的mixin参数...

.btn-custom {
    @include button-variant(pink, red, red, #444, #333, red);
    color: #fff;
}

https://www.codeply.com/go/EHwnjvUXac

相关:Extending Bootstrap 4 and SASS