Twitter Bootstrap 3.0 how do I “badge badge-important” now

后端 未结 9 1725
执念已碎
执念已碎 2021-01-29 19:01

In version two I could use

badge badge-important

I see that the .badge element no longer has contextual (-success,-primary,etc..) c

相关标签:
9条回答
  • 2021-01-29 19:54

    When using the LESS version you can import mixins.less and create your own classes for colored badges:

    .badge-warning {
        .label-variant(@label-warning-bg);
    }
    

    Same for the other colors; just replace warning with danger, success, etc.

    0 讨论(0)
  • 2021-01-29 19:55

    Well, this is a terribly late answer but I think I'll still put my two cents in... I could have posted this as a comment because this answer doesn't essentially add any new solution but it does add value to the post as yet another alternative. But in a comment I wouldn't be able to give all the details because of character limit.

    NOTE: This needs an edit to bootstrap CSS file - move style definitions for .badge above .label-default. Couldn't find any practical side effects due to the change in my limited testing.

    While broc.seib's solution is probably the best way to achieve the requirement of OP with minimal addition to CSS, it is possible to achieve the same effect without any extra CSS at all just like Jens A. Koch's solution or by using .label-xxx contextual classes because they are easy to remember compared to progress-bar-xxx classes. I don't think that .alert-xxx classes give the same effect.

    All you have to do is just use .badge and .label-xxx classes together (but in this order). Don't forget to make the changes mentioned in NOTE above.

    <a href="#">Inbox <span class="badge label-warning">42</span></a> looks like this:

    IMPORTANT: This solution may break your styles if you decide to upgrade and forget to make the changes in your new local CSS file. My solution for this challenge was to copy all .label-xxx styles in my custom CSS file and load it after all other CSS files. This approach also helps when I use a CDN for loading BS3.

    **P.S: ** Both the top rated answers have their pros and cons. It's just the way you prefer to do your CSS because there is no "only correct way" to do it.

    0 讨论(0)
  • 2021-01-29 20:03

    Bootstrap 3 removed those color options for badges. However, we can add those styles manually. Here's my solution, and here is the JS Bin:

    .badge {
      padding: 1px 9px 2px;
      font-size: 12.025px;
      font-weight: bold;
      white-space: nowrap;
      color: #ffffff;
      background-color: #999999;
      -webkit-border-radius: 9px;
      -moz-border-radius: 9px;
      border-radius: 9px;
    }
    .badge:hover {
      color: #ffffff;
      text-decoration: none;
      cursor: pointer;
    }
    .badge-error {
      background-color: #b94a48;
    }
    .badge-error:hover {
      background-color: #953b39;
    }
    .badge-warning {
      background-color: #f89406;
    }
    .badge-warning:hover {
      background-color: #c67605;
    }
    .badge-success {
      background-color: #468847;
    }
    .badge-success:hover {
      background-color: #356635;
    }
    .badge-info {
      background-color: #3a87ad;
    }
    .badge-info:hover {
      background-color: #2d6987;
    }
    .badge-inverse {
      background-color: #333333;
    }
    .badge-inverse:hover {
      background-color: #1a1a1a;
    }
    
    0 讨论(0)
提交回复
热议问题