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.

Updated .bg-* and .text-* utilities break when CSS variables are not enabled in v5.1.0

See original GitHub issue

In one of my projects I include the needed Bootstrap SCSS files manually and specifically exclude bootstrap/scss/root, first because I don’t rely on most of the CSS variables and secondly because adding all CSS variables increases the CSS file size by about 50-60kb (uncompressed).

With v5.1.0 all .bg-* and .text-* utilities break, as the needed CSS variables are missing, e.g.

.text-white {
    --bs-text-opacity: 1;
    color: rgba(var(--bs-white-rgb), var(--bs-text-opacity)) !important; // --bs-white-rgb is not set
}

Is there a simple way to disable CSS variables generation or to reduce the number of CSS variables? The only way forward right now would be to revert the utility sets back to $theme-colors, but that still leaves an additional --bs-text-opacity: 1; and does not take care of --bs-body-color and the like:

$utilities-text-colors: $theme-colors;
$utilities-bg-colors: $theme-colors;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:39 (16 by maintainers)

github_iconTop GitHub Comments

16reactions
iatekcommented, Aug 24, 2021

The whole bg-, text- update in 5.1.0 has seemingly complicated the entire process of adding a new theme-color. The only way I could find to get the bg- and text- classes regenerated for the new “custom” theme color is…

@import "functions";
@import "variables";
@import "mixins";

$custom: #df711b;

$custom-theme-colors: (
  "custom": $custom
);

$theme-colors: map-merge($theme-colors, $custom-theme-colors);
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$utilities-colors: map-merge($utilities-colors, $theme-colors-rgb);
$utilities-text-colors: map-loop($utilities-colors, rgba-css-var, "$key", "text");
$utilities-bg-colors: map-loop($utilities-colors, rgba-css-var, "$key", "bg");

@import "bootstrap";

I discovered this on an SO question and here’s the working code demo


Whereas in 5.0.2 one could simply follow the example in the docs…

@import "functions";
@import "variables";
@import "mixins";

$custom-colors: (
  "custom-color": #df711b
);

$theme-colors: map-merge($theme-colors, $custom-colors);
7reactions
Pythaguscommented, Aug 19, 2021

The whole bg-, text- update in 5.1.0 has seemingly complicated the entire process of adding a new theme-color. The only way I could find to get the bg- and text- classes regenerated for the new “custom” theme color is…

@import "functions";
@import "variables";
@import "mixins";

Thanks! This really needs to be written in the official documentation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap Blog · Official blog for the Bootstrap framework.
Fixed broken .bg-body utility. This was caused by the same --body-rgb CSS variable for both text and background. --body-rgb is now split ......
Read more >
Background · Boosted v5.1
1.0, background-color utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha ...
Read more >
Breaking Change: CSS Variable Syntax - Sass
When they were parsed as SassScript values, syntax that would have been valid plain CSS failed to parse. For example, the Polymer library...
Read more >
HTML Standard
In parallel with this, the W3C also worked on a new language that was not ... here by "␣") and line breaks ("⏎")...
Read more >
var() - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The var() CSS function can be used to insert the value of a custom property (sometimes called a "CSS variable") instead of any...
Read more >

github_iconTop Related Medium Post

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