question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apply .text-dark for .badge with some .bg-* classes

See original GitHub issue

In Bootstrap 4, class="badge badge-light" was enough, but in Bootstrap 5, it’s class="badge bg-light text-dark". This is less convenient when switching between badge bg-dark and badge bg-light, since text-dark also has to be added or removed.

Bootstrap 5 should apply the styles for text-dark to .badge.bg-light and .badge.bg-warning. The Bootstrap 5 docs also recommend text-dark for bg-info, but I find that one is not necessary.

One workaround is to add this to our SCSS files, which is what Bootswatch does:

@import "~bootstrap/scss/bootstrap";

.badge {
  &.bg-warning,
  &.bg-info, /* optional */
  &.bg-light {
    @extend .text-dark;
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
florianlacreusecommented, May 19, 2021

We don’t use yet BS5 in real development projects but I agree with @theonlypwner, having to specify the color makes the use of badges less simple (imho).

We had already planned to add an override on our side to fix this. @ffoodd Thanks for the idea used in your BS fork (nice project btw), I’ll use it if BS don’t add pairing constraints for color and background-color.

So +1 to not have to add text color css class while using BS badge, background, etc., whatever the solution is.

2reactions
florianlacreusecommented, Nov 3, 2021

With this issue still open, what’s the status of the problem on the Bootstrap team side? For end users, the previous badge color scheme was much simpler. IMHO, for badges we should not have to choose the color of the text.

If there are too many side effects by changing the backgrounds utilities, may be badge-${color} should be reintroduced?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Badges · Bootstrap v5.0
Use our background utility classes to quickly change the appearance of a badge. Please note that when using Bootstrap's default .bg-light , you'll...
Read more >
Bootstrap Badges -- Tutorials with advanced examples
Use our background utility classes to quickly change the appearance of a badge. ... <span class="badge bg-warning text-dark">Warning</span>
Read more >
Bootstrap Badges - Examples & Tutorials. Learn how to use ...
Contextual variations. Add any of the below-mentioned classes to modify the presentation of a badge. Please note that when using Bootstrap's default .bg-light ......
Read more >
Bootstrap 5 Badges Background colors - GeeksforGeeks
The default background of any badge is “.bg-light“, which can be used with text color utility, like .text-dark class, which helps to enhance ......
Read more >
Bootstrap 5 Badges - Bootstrap CSS tutorial - Devwares
<span class="badge bg-light text-dark ml-2">4</span> ... Flat Badges. To remove shadows from your badges, use the badge-flat class. Bootstrap Badges Flat ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found