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.

Bootstrap v4 - Overriding Mixins

See original GitHub issue

Has any thought been put into overriding Bootstrap mixins?

I have a use case, where for example, I want to override the definition of a bootstrap mixin to provide additional styles, or modify existing styles slightly.

The problem with this is that SASS does not use the overridden mixin in certain cases, such as in an @include statement.

(More details here: https://github.com/sass/sass/issues/240)

For example, I’ve overriden the color-yiq mixin, and then the button-variant mixin. The button-variant mixin uses the correct (redefined) color-yiq mixin, because it was defined prior to the redefinition of the button-variant mixin.

However, the badge-variant mixin references the previously defined color-yiq mixin, because I have not overridden the badge-variant mixin.

The flow is something like:

  • color-yiq defined by Bootstrap
  • button-variant mixin defined by Bootstrap
  • badge-variant mixin defined by Bootstrap
  • color-yiq redefined by me
  • button-variant redefined be me

The output looks like the following (pay attention to the text colour for the btn-warning and badge-warning):

image

It would seem that the only way around this that I can think of is to redefine every single mixin that uses the color-yiq mixin, which seems massively overkill.

I can’t be the only person in the world who would want to override a Bootstrap SASS mixin, surely?

Any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
richardthombscommented, Jun 6, 2019

I’ve been trying to implement disabling of the :hover styles when the device doesn’t support hover and I wanted to override the mixins too. I ended up overriding all the :hover styling with the non-hovered versions, which sucks. +1 for having some kind of ability to override the mixins.

3reactions
francescozaiacommented, Nov 24, 2017

Indeed. It is quite opinionated to have this code in a mixin: @if ($yiq >= 150) { @return #111; } @else { @return #fff; } What about having these two colors available as variables maybe?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to override Bootstrap mixin without modifying the actual ...
Best solution would be to override whole button-variant mixin in Bootstrap before compilation so that in compiled Bootstrap file there is only css...
Read more >
Theming Bootstrap
In Bootstrap 3, theming was largely driven by variable overrides in LESS, custom CSS, and a separate theme stylesheet that we included in...
Read more >
Customizing Bootstrap 4 (specific modules and overriding ...
Hi I need to include specific css/js modules of Bootstrap 4 and not the entire ... Then I need to: 1- override Bootstrap...
Read more >
How to override Bootstrap CSS? - Themesberg
We recommend using Sass variables because that will not override the regular CSS from Bootstrap, but in fact, change it altogether. However, I ......
Read more >
How to Edit, Customize, and Override Bootstrap CSS to Suit ...
You can override the default styles of Bootstrap elements using two possible methods. The first way — using CSS overrides— applies to sites ......
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