Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap set badge to no fill (or outline)?

Anyone know how to change a twitter bootstrap badge (or label) from solid to outlined?

enter image description here

like image 919
Meltemi Avatar asked Jan 31 '13 07:01

Meltemi


3 Answers

Quick bootstrap 4 sass version

@each $color, $value in $theme-colors {
  .badge-outline-#{$color} {
    border: $border-width solid $value;
    color: $value !important;
    background: transparent !important;
  }
}
like image 164
b4sass Avatar answered Oct 17 '22 17:10

b4sass


Add this CSS class to your badge :

.badge-outline {
    color: black;
    border: 1px solid #999;
    background-color: transparent;
}

Create overriden classes for other colors :

.badge-outline.badge-success {
    border-color: #468847;
}
like image 31
SJousse Avatar answered Oct 17 '22 15:10

SJousse


The typical boostrap configuration for badges has these key parts related to your question (spread out in their labels-badges.less):

Current Bootstrap

.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%); }
}

So you can override it by following that with something like this:

Override in your later LESS code

.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
}
like image 4
ScottS Avatar answered Oct 17 '22 17:10

ScottS