I have just started a new project using Bootstrap 5 and I am trying to set up theme-colors with some custom values. However doing it the way that I have always done it is giving me some issues.
I have created three colors: $primary, $secondary, $tertiary. However if I add any classes such as bg-tertiary, then nothing changes as if it doesn't exist. bg-primary simply uses the default color defined by Bootstrap.
My code below:
@import "bootstrap/_functions";
@import "bootstrap/_variables";
$primary: #ec008c;
$secondary: #1ab7ea;
$tertiary: #3fb247;
$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"tertiary": $tertiary,
"light": $light,
"dark": $dark,
);
@import "bootstrap/bootstrap";
If I change a default value such as "dark" to use $tertiary then any code within the scss file using $dark changes to use the value from $tertiary. Like below:
$theme-colors(
"dark": $tertiary
);
#pageFooter {
background: $dark; //This becomes #3fb247 the value from $tertiary
}
What am I doing wrong? I can't understand why the variables in the scss file are being affected by the change to $theme-colors, but classes are not.
Edit:
Using chrome inspector I can see that .bg-primary uses a css variable --bs-primary-rgb. Looking at the available variables --bs-primary has changed to the color that I have set, but not --bs-primary-rgb.
How can I have this variable be changed. Should it be done automatically?
With further research these rgb variables appear to have been introduced in Bootstrap 5.1. I can't find much information about how to get the variable to update to my set values probably because it is too new. So I have chosen to revert back to 5.0.2 and everything is now working as I expect it to.