Apply .text-dark for .badge with some .bg-* classes
See original GitHub issueIn 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:
- Created 2 years ago
- Reactions:4
- Comments:13 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
andbackground-color
.So +1 to not have to add text color css class while using BS
badge
,background
, etc., whatever the solution is.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?