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.

How to override theme colors now?

See original GitHub issue

I’ve noticed in _variables.scss that the brand colours have been moved to a nested object.

Up to now, I‘ve been specifying variable overrides in a _custom.scss in my projects like this:

@import "custom";
@import "node_modules/bootstrap/scss/bootstrap";

I’d then override the variables I wanted in my _custom.scss file like this:

$brand-primary: #fc0;

$font-family-sans-serif: "Open Sans", sans-serif;

How do I override values on a per-variable basis now that they’re inside an object? For example, I have a project where I want the brand’s primary color to be green and not blue.

Sorry if this a n00b question, but I’m under the impression that object members like $theme-colors[primary] aren’t overridable in Sass without overriding the whole object, in which case these seriously reduces the configurability of Bootstrap in version 4.

If I’m doing something wrong, or I can override specific members of objects in Sass, then please let me know.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

17reactions
martinbeancommented, Sep 24, 2017

is the biggest concern that this feels heavy handed when compared to the old $brand-{color} variables?

@mdo Exactly that. When overriding a $brand-{color} variable, I’m overriding what I want, and only what I want. To copy over a whole Sass map just to change one colour in that map just seems overly cumbersome, especially when I also have to re-define the individual colour variables referenced in that map, i.e. $blue et al. So changing the primary color goes from this:

$brand-primary: #006600;

To this:

$gray-100: #f8f9fa;
$gray-600: #868e96;
$gray-800: #343a40;

$red: #dc3545;
$yellow: #ffc107;
$green: #006600; // This is the only variable I wanted to change
$cyan: #17a2b8;

$theme-colors: (
  primary: $green,
  secondary: $gray-600,
  success: $green,
  info: $cyan,
  warning: $yellow,
  danger: $red,
  light: $gray-100,
  dark: $gray-800
);
17reactions
houfiocommented, Jul 18, 2017

If you don’t need any of the other colors you can just do

$theme-colors: (
  primary: #006400
)

since all the calls to the map are loops.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Discover how to override theme colors in Bootstrap 5 using Sass
1 Bootstrap Sass override variables by using the right import sequence · 2 Bootstrap 5 changes the $theme-colors definition · 3 Bootstrap 5 ......
Read more >
Unable to override $theme-color in bootstrap - Stack Overflow
To change the primary, or any of the theme colors in Bootstrap 4 SASS, set the appropriate variables before importing bootstrap.scss . This ......
Read more >
How to: Override Theme Colors | WPF Controls
The following example demonstrates how to override colors defined by the current theme. In this example, we have created a black-and-white ...
Read more >
Shopify CSS Intro - How to Overwrite Theme Colors and Fonts ...
How to make precise design changes that go beyond what the theme settings allow. This is one of the first videos I'm doing...
Read more >
Theming Bootstrap
// Custom.scss // Option A: Include all of Bootstrap ; // Custom.scss // Option B: Include parts of Bootstrap ; // Your variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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