Last active
September 26, 2020 10:01
-
-
Save amrography/bef93585010cac1283ab9c44c63cc73e to your computer and use it in GitHub Desktop.
Extend bootstrap 4 with transparent background from bootstrap theme colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should load it after declaring
$theme-colors
variable, or after importingbootstrap.scss
.