2

How can add custom new theme color without touching bootstrap variable.scss?

Please note I can update the existing color successfully, but I couldn't add new theme color in that same way

File structure

@import 'custom_variables';
@import './bootstrap/bootstrap'; 
@import './pages/home';

custome_variables.scss

$theme-colors: (
    "primary": #2c67f4, // successfully edited existing color  
    "danger": #ff4136,
    "custom" : "red" // not working when adding new color theme
);

Tried with code but no luck

$theme-colors: map-merge(
  (
    "custom":  "red",
  ),
  $theme-colors
);

Reference

ShibinRagh
  • 6,530
  • 4
  • 35
  • 57

3 Answers3

2

You have to import the variables first...

/* import the necessary Bootstrap files */
@import "bootstrap/functions";
@import "bootstrap/variables";

$theme-colors: (
    "primary": #2c67f4,
    "danger": #ff4136,
    "custom" : red
);

@import "bootstrap";

https://www.codeply.com/go/mdlTSDbmUG

Also see: Customizing Bootstrap CSS template

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
1

$theme-colors: (
  "custom-color": #900
);
<button class="btn btn-custom-color">Sign up free</button>

Try this! It worked for me.

nazifa rashid
  • 1,469
  • 1
  • 9
  • 20
1

When dealing with bootstrap changes the imports order is crucial. I went one step further and used updated mapping to create summary mapping for all colors, but for no reason (like i thought) my new colors were in theme-colors, they were working fine, but all-colors mapping had just my local update, so what i had to do was to import once again the updated variable from bootstrap. Here's my assets structure:

_variables.scss

@import "~bootstrap/scss/functions"; // import only required things
@import "~bootstrap/scss/variables";              

$theme-colors: (                                   
    'error': $danger,                              
    'warn': $warning,                              
);                                               

// reimport to use updated mapping, not only local one                                          
@import "~bootstrap/scss/variables";           

$all-colors: () !default;                          
$all-colors: map-merge($all-colors, $theme-colors);
$all-colors: map-merge($all-colors, $colors);      
$all-colors: map-merge($all-colors, $grays); 

style.scss

@import 'variables';                  
@import 'exports';                    
@import 'functions';                  
@import '~bootstrap/scss/bootstrap'; 
@import 'custom';  
Karolius
  • 543
  • 1
  • 6
  • 12