"There must be a function to modify the text color according to the
color brightness in bootstrap."
Yes, it's using the WCAG 2.0 algorithm explained here. The red color you're using is just light enough to flip the text color to dark according to the WCAG algorithm.
Buttons are created by mixins (see: Buttons in the docs). In this case the 3rd parameter of the button-variant
mixin $color
is defined as:
$color: color-contrast($background, $color-contrast-dark, $color-contrast-light, $min-contrast-ratio)
So the button's color is either $color-contrast-dark
or $color-contrast-light
, depending on the WCAG 2.0 calculation using the $min-contrast-ratio
.
Therefore, making the custom red color color slightly darker will flip the text color to white...
$primary: #d73b11;
@import "bootstrap";
Or, you can use the original custom color and force white bold text on btn-primary
like this...
$primary: #e84c22;
@import "bootstrap";
.btn-primary {
color: #fff;
font-weight: bold;
}
Demo
Or,
You can set a lower value on the $min-contrast-ratio
variable (3, 4.5, and 7 are the acceptable values) as shown in this answer
Also note that the way you're re-defining the theme-color map is wiping out all the other theme colors. You only need to change the value of $primary to change the primary theme color.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…