Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create new set of color styles in Bootstrap 4 with sass

I'm starting to navigate through the wonderful Bootstrap 4 and I'm wondering how to add a whole new set of elements color to the _custom.scss

Example: Right now you have btn-danger, text-danger etc... how to create for example, using a random name: "crisp" set... so you will have btn-crisp, text-crisp etc...

My guess would be to start with adding a variable

$brand-crisp: #color !default;

But, then what? Thanks! I appreciate your help.

like image 536
Kitara Avatar asked Sep 08 '16 04:09

Kitara


People also ask

Does Bootstrap 4 support Sass?

Sass optionsCustomize Bootstrap 4 with our built-in custom variables file and easily toggle global CSS preferences with new $enable-* Sass variables. Override a variable's value and recompile with npm run test as needed. You can find and customize these variables for key global options in Bootstrap's scss/_variables.

How do I change colors in SCSS?

Sass Set Color Functions An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of that color and can be an integer between 0 and 255, or a percentage value (from 0% to 100%). Sets a color using the Red-Green-Blue-Alpha (RGBA) model.


2 Answers

There is not an all inclusive color mixin, so I think you need to use the mixins individually...

.btn-custom {
    @include button-variant(#cece19, #222222, #cece19);
}

.btn-custom-outline {
    @include button-outline-variant(#222222);
}

.card-custom {
    @include card-variant(#aa9999, #997777)
}

http://www.codeply.com/go/MKGQCrLwDs


Update: In Bootstrap 4, you now can create a new custom "theme-color" to as explained in my answer here. This will allow you to use the color anywhere such as btn-custom, text-custom, bg-custom, etc...

Update Bootstrap 4.1

The button mixins have changed slightly and now require add'l params...

.btn-custom {
    @include button-variant(#cece19, #222222, #cece19, #cece19, #cece19, #cece19);
}

.btn-custom-outline {
    @include button-outline-variant(#222222, #cece19, #222222, #cece19);
}

@import "bootstrap";
like image 107
Zim Avatar answered Nov 24 '22 05:11

Zim


You're in luck, because today I just released an online tool that does exactly that: https://lingtalfi.com/bootstrap4-color-generator.

It will generate the necessary css code (using sass or not as an option), and will generate the 10 color variations for bootstrap4 colors.

In the end, I recommend creating a custom "my_colors.css" (or my_colors.scss) file, and put all your generated colors in it.

Note that my tool only changes colors, it doesn't care about other properties (padding, font-size, etc...).

Hope this helps.

like image 29
ling Avatar answered Nov 24 '22 04:11

ling