Twitter Bootstrap将徽章设置为无填充(或轮廓)?

Mel*_*emi 7 sass outline less badge twitter-bootstrap

任何人都知道如何将twitter引导徽章(或标签)从实体更改为轮廓?

在此输入图像描述

IAm*_*NaN 9

Bootstrap 5 直接支持您想要的效果。边界不仅创建轮廓,还允许控制颜色和厚度。

此示例使用徽章上的border和来创建蓝色轮廓。border-primary为了使“3”与轮廓的颜色相匹配,它还使用了text-primary。请注意,它仅使用badge类,而不是badge-primary因为这也会将背景颜色更改为蓝色。

<span class="badge border border-primary text-primary">3</span>
Run Code Online (Sandbox Code Playgroud)


SJo*_*sse 7

将此CSS类添加到徽章:

.badge-outline {
    color: black;
    border: 1px solid #999;
    background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

为其他颜色创建覆盖类:

.badge-outline.badge-success {
    border-color: #468847;
}
Run Code Online (Sandbox Code Playgroud)


小智 6

快速引导4 sass版本

@each $color, $value in $theme-colors {
  .badge-outline-#{$color} {
    border: $border-width solid $value;
    color: $value !important;
    background: transparent !important;
  }
}
Run Code Online (Sandbox Code Playgroud)


Sco*_*ttS 5

徽章的典型Boostrap配置具有与您的问题相关的以下关键部分(在中扩展了labels-badges.less):

当前引导

.badge {
    color: @white;
    background-color: @grayLight;
    /* no border is set, just a border-radius: 9x */
}

.badge {
  // Important (red)
  &-important { background-color: @errorText; }
  &-important[href] { background-color: darken(@errorText, 10%); }

  // Warnings (orange)
  &-warning { background-color: @orange; }
  &-warning[href] { background-color: darken(@orange, 10%); }

  // Success (green)
  &-success { background-color: @successText; }
  &-success[href] { background-color: darken(@successText, 10%); }

  // Info (turquoise)
  &-info { background-color: @infoText; }
  &-info[href] { background-color: darken(@infoText, 10%); }

  // Inverse (black)
  &-inverse { background-color: @grayDark; }
  &-inverse[href] { background-color: darken(@grayDark, 10%); }
}
Run Code Online (Sandbox Code Playgroud)

因此,您可以通过以下操作覆盖它:

覆盖您以后的LESS代码

.badge {
    color: @black;
    background-color: transparent;
    border: 1px solid @grayLight; /* set your border */
}

.badge {
  // Important (red)
  &-important { background-color: transparent;
                border-color: @errorText;
                color: #errorText; /* maybe change color? up to you. */
              }
  &-important[href] { background-color: transparent;
                      border-color: darken(@errorText, 10%); 
                      color: darken(@errorText, 10%); /* ??? */
              }

  etc... for -warning, -success, -info, -inverse
}
Run Code Online (Sandbox Code Playgroud)