17

我想在我的自定义主题中对 .navbar-inner 进行子类化,但我想不出一种非黑客的方式来禁用渐变(除了将两种渐变颜色设置为看起来很脏的相同颜色)。知道如何在 less 中覆盖(禁用)子类中的 mixin 吗?

4

5 回答 5

14

这就是您需要在 css 中实现以覆盖禁用渐变。

CSS:

.navbar-inner {
  background-color: #2c2c2c; 
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-repeat: no-repeat;
  filter: none;
}

background-image: none;必须多次使用才能覆盖所有供应商前缀。

去除渐变

于 2012-07-04T20:28:13.613 回答
5

对于 SASS 代码:我添加了 background-color:transparent 并将其移至 mixin

@mixin override_gradient_vertical() {
  background-color:transparent;
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-image: none;
  background-repeat: no-repeat;
  filter: none;
}

现在你可以使用

@include override_gradient_vertical();
于 2012-08-21T15:52:30.643 回答
3

感谢您的解决方案。只是分享我在阅读答案后的想法:

这是我用来删除简单渐变的 SCSS:

@mixin remove_gradient($color:transparent) {
    background-color:$color;
    background-image: none;
    background-repeat: no-repeat;
    filter: none;
}

请注意,您可以将颜色传递给 mixin(在我的情况下需要):

@include remove_gradient(white);

或者让它默认为透明:

@include remove_gradient();
于 2013-07-16T01:38:13.247 回答
1

渐变由 bootstrap_theme 文件添加。

我真的不喜欢没有这么多背景图像的想法。所以我的解决方案是,如果您使用的是 SASS 或 LESS 版本的引导程序,只需通过 _theme.scss 中最初存在的以下行覆盖渐变

.navbar-default {
  @include gradient-vertical($start-color: lighten($navbar-default-bg, 10%), $end-color: $navbar-default-bg);
  @include reset-filter(); // Remove gradient in IE<10 to fix bug where dropdowns don't get triggered
  border-radius: $navbar-border-radius;
  $shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 1px 5px rgba(0,0,0,.075);
  @include box-shadow($shadow);

  .navbar-nav > .active > a {
    @include gradient-vertical($start-color: darken($navbar-default-bg, 5%), $end-color: darken($navbar-default-bg, 2%));
    @include box-shadow(inset 0 3px 9px rgba(0,0,0,.075));
  }
}

.navbar-default {
  @include gradient-vertical($start-color: $navbar-default-bg, $end-color: $navbar-default-bg);
  @include reset-filter(); // Remove gradient in IE<10 to fix bug where dropdowns don't get triggered

  $shadow: inset 0 0px 0 rgba(255,255,255,.15), 0 0px 0px rgba(0,0,0,.075);
  @include box-shadow($shadow);

  .navbar-nav > .active > a {
    @include gradient-vertical($start-color: $navbar-default-bg, $end-color: $navbar-default-bg);
    @include box-shadow(inset 0 0px 0px rgba(0,0,0,.075));
  }
}

如您所见,起点和终点是相同的值,因此我们永远不会看到渐变效果。简单而干净。

于 2015-03-04T09:49:28.160 回答
1

因为它的价值在于较少的实现。引导文件 mixin.less

#gradient{
    .remove(@color: transparent) {
        background-color:@color;
        background-image: none;
        background-repeat: no-repeat;
        filter: none;
    }
}
于 2014-02-11T02:25:35.937 回答