Skip to content

Instantly share code, notes, and snippets.

@amrography
Last active September 26, 2020 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrography/bef93585010cac1283ab9c44c63cc73e to your computer and use it in GitHub Desktop.
Save amrography/bef93585010cac1283ab9c44c63cc73e to your computer and use it in GitHub Desktop.
Extend bootstrap 4 with transparent background from bootstrap theme colors
/**
* USAGE
*
* <div class="bg-light-65"></div>
* <div class="bg-primary-20"></div>
*
* <a href="#" class="btn btn-danger-50">Button too</a>
* ...
*/
// variables
$opacity: 10; //opacity start value
$opacity_step: 5; //increase opacity by .5
// Mixin
@mixin bg-variant-transparent($parent, $color, $opacity) {
#{$parent} {
background: rgba($color, $opacity) !important;
}
a#{$parent},
button#{$parent} {
@include hover-focus {
background-color: rgba(darken($color, 10%), $opacity) !important;
}
}
}
// Loop
@each $color, $value in $theme-colors {
@while $opacity < 90 {
@include bg-variant-transparent(
".bg-#{$color}-#{$opacity}",
$value,
($opacity/100)
);
$opacity: $opacity + $opacity_step;
}
}
@amrography
Copy link
Author

You should load it after declaring $theme-colors variable, or after importing bootstrap.scss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment