Use SASS to customize button colors - sass
I'm only opening this topic because I don't have the necessary 50 reputation points to ask my question directly into the topic I'm interested in.
So, my problem is that I need 25 bootstrap buttons of specific colors (that the user will use to choose among some Pantone variations etc). I found this great topic how to change bootstrap version 4 button color where Zim suggests a SASS solution that obviously saves a lot of CSS writing for the various button states/borders/etc...
However, as I'm new to SASS, I don't understand how it's supposed to be implemented in my webpage. More specifically, I don't know where to put the mentioned color variable and new button classes.
Currently I use this https://www.codeply.com/go/76H7JWg7Zl but of course the border/mouseover/etc use the primary color of the btn-primary class...
After studying the scss source files of bootstrap and also some online resources, I ended up that defining the following SASS mixins would solve my problem:
#import "bootstrap";
.btn-ffa300 {
#include button-variant(#ffa300, darken(#ffa300, 5%));
}
.btn-ffd700 {
#include button-variant(#ffd700, darken(#ffd700, 5%));
}
.btn-97d700 {
#include button-variant(#97d700, darken(#97d700, 5%));
}
.btn-012169 {
#include button-variant(#012169, darken(#012169, 5%));
}
.btn-001489 {
#include button-variant(#001489, darken(#001489, 5%));
}
.btn-ff8200 {
#include button-variant(#ff8200, darken(#ff8200, 5%));
}
.btn-c4d600 {
#include button-variant(#c4d600, darken(#c4d600, 5%));
}
.btn-84bd00 {
#include button-variant(#84bd00, darken(#84bd00, 5%));
}
.btn-0033a0 {
#include button-variant(#0033a0, darken(#0033a0, 5%));
}
.btn-c8c9c7 {
#include button-variant(#c8c9c7, darken(#c8c9c7, 5%));
}
.btn-ff6900 {
#include button-variant(#ff6900, darken(#ff6900, 5%));
}
.btn-78d64b {
#include button-variant(#78d64b, darken(#78d64b, 5%));
}
.btn-009ca6 {
#include button-variant(#009ca6, darken(#009ca6, 5%));
}
.btn-002d72 {
#include button-variant(#002d72, darken(#002d72, 5%));
}
.btn-7c878e {
#include button-variant(#7c878e, darken(#7c878e, 5%));
}
.btn-ff6a13 {
#include button-variant(#ff6a13, darken(#ff6a13, 5%));
}
.btn-ef3340 {
#include button-variant(#ef3340, darken(#ef3340, 5%));
}
.btn-69b3e7 {
#include button-variant(#69b3e7, darken(#69b3e7, 5%));
}
.btn-002f6c {
#include button-variant(#002f6c, darken(#002f6c, 5%));
}
.btn-63666a {
#include button-variant(#63666a, darken(#63666a, 5%));
}
.btn-fe5000 {
#include button-variant(#fe5000, darken(#fe5000, 5%));
}
.btn-c8102e {
#include button-variant(#c8102e, darken(#c8102e, 5%));
}
.btn-003da5 {
#include button-variant(#003da5, darken(#003da5, 5%));
}
.btn-002855 {
#include button-variant(#002855, darken(#002855, 5%));
}
.btn-4f2c1d {
#include button-variant(#4f2c1d, darken(#4f2c1d, 5%));
}
I even confirmed that it's working by rewriting my previous fiddle, and indeed the result ended up EXACTLY as I wanted it to be (https://www.codeply.com/go/uYPxiuNkbu).
Codeply is also "kind enough" to provide in the appropriate tab the compiled css of the sass code used in the fiddle...
But that's an indirect way of preprocessing the sass code... What would a proper way be? Isn't there some sort of online CSS preprocessor? Ie, I read that (https://themestr.app/customize) can be used to customize bootstrap code and then all customizations end up in a compiles custom.css file... How does that work? So far I haven't succeed in achieving this. Some help with this please?
If you want to learn SASS you can go through their official website. If you know css sass won't be a tough one to learn.
For installing gulp there are lots of tutorials you can find!
https://css-tricks.com/gulp-for-beginners/ Here is the one that you can go through.
For using bootstrap 4 theming if you wish you can just learn sass basics and gulp is not required much. You can use propos instead of gulp.
You can simply follow the below steps
To install bootstrap on any local project:
npm init -y
npm install
npm install bootstrap --save
To run manually (Without Gulp):
sass path/filename.sass/filename.scss filename.css
After creating new theme you can use it the same way you're using bootstrap theme. For example: <button class="btn btn-custom-color"></button>
Hope it'll help
/* Change theme color */
$theme-colors: (
"info": #7eff4b,
"danger": #ff50f0,
"primary": #0095ff,
"secondary": #28a745
);
/* Create your own theme */
$theme-colors: (
"custom-color": #900
);
Related
How do i change material.io web component fill-color (mdc-top-app.bar)
I have been looking into google material design for web and am also totally new to SASS. As it stands, i have been trying to change the background-color for the mdc-top-app-bar using the sass mixin fill-color($color) provided in the framework. Having tried these few lines #use '#material/button/mdc-button'; #use '#material/button'; #use "#material/top-app-bar/mdc-top-app-bar"; #use "#material/icon-button/mdc-icon-button"; .mdc-top-app-bar { #include mdc-top-app-bar.fill-color(#8e44ad); } Am displayed with the follow error messages ERROR in ./app.scss Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: Undefined mixin. ╷ 10 │ #include mdc-top-app-bar.fill-color(#8e44ad); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I completely cooked the last answer but I have worked it out. instead of: #use "#material/top-app-bar/mdc-top-app-bar"; #use "#material/icon-button/mdc-icon-button"; use: #import "#material/top-app-bar/mdc-top-app-bar"; #import "#material/icon-button/mdc-icon-button"; and then to use the mixin, instead of: .mdc-top-app-bar { #include mdc-top-app-bar.fill-color(#8e44ad); } use: .mdc-top-app-bar { #include mdc-top-app-bar-fill-color(#8e44ad); } I hope this helps --Nathaniel
To avoid import statement you should do: #use "#material/top-app-bar"; and then .mdc-top-app-bar { #include top-app-bar.fill-color(#8e44ad); } Also you can create alias #use "#material/top-app-bar" as topbar; .mdc-top-app-bar { #include topbar.fill-color(#8e44ad); }
Sass: Setting global variables based on theme
I am trying to set global variables when a theme mixin is included since it seems much more straight-forward to use than this "themify" stuff I find from searching. The idea is something like having a _themes.scss with #mixin light-theme { $primary-color: #123456 !global; } #mixin dark-theme { $primary-color: #654321 !global; } body.light-theme { #include light-theme } body.dark-theme { #include dark-theme } The problem is it always uses the dark-theme value since it is declared last. Is what I am trying to do possible?
Define multiple grids in Singularitygs v1.4
I started upgrading a website from Singularity 1.1.2 to 1.4.0 and immediately hit a wall when it came to using multiple grids in the same style sheets. I have five different grids on this site. Previously I was able to set variables for each of the grids and gutters, like so... $copy-grids: 2; $copy-grids: add-grid(4 at $breakpoint-xs-min, $copy-grids); $copy-grids: add-grid(6 at $breakpoint-l-min, $copy-grids); $copy-gutters: $gutter-width; $front-grids: 1; $front-grids: add-grid(2 at $breakpoint-2up-min, $front-grids); $front-grids: add-grid(3 at $breakpoint-3up-min, $front-grids); $front-grids: add-grid(4 at $breakpoint-4up-min, $front-grids); $front-gutters: breakpoint-to-base-em($front-gutter-width); ... Then I was able to pass these variables to custom mixins using Singularity's layout() function, like this... // Mixins for the main content body copy. #mixin copy-layout { #include layout($copy-grids, $copy-gutters) { // All the things! #content; } } #mixin copy-grid-span($span, $location) { #include copy-layout { #include grid-span($span, $location); } } // Mixins for the front page. #mixin front-layout { #include layout($front-grids, $front-gutters) { $gutter-styles: 'split' 'fixed'; // All the things! #content; } } #mixin front-grid-span($span, $location) { #include front-layout { #include grid-span($span, $location); } } ... This let me use my custom mixins in place of the standard grid-span() mixins to easily implement any of my defined grids. For instance: #block-bean-front-page-message { margin-bottom: $front-gutters; #include breakpoint-1up() { width: 100%; padding: 0 $front-gutters/2; } #include breakpoint-2up-to-4up() { #include front-grid-span(1, 2); } #include breakpoint-4up(true) { #include front-grid-span(3, 2); } } The problem is that, in Singularity v1.4, grid and gutter settings are no longer saved to normal sass variables. Instead they are saved as keyed values in the global $Singularity-Settings map. The keys used for these values are hard coded in the add-grid(), add-gutter(), and add-gutter-style() mixins, none of which accept a custom variable name. This appears to effectively prevent me from defining more than one grid. So while the layout() mixin still exists, I no longer have variables I can pass into it for my grid and gutter settings, breakng my custom layout wrapper mixins. I've posted this as an issue on Github and I understand a more permanent fix may be in the works. But in the mean time, I'm hoping there is a workaround I can use to accomplish multiple grids using the current release of Singularity.
It looks like I'm able to achieve what I'm after by overriding the add-grid(), add-gutter(), and add-gutter-style() mixins like so: #mixin add-grid($grid-definition, $grid-key: 'grids') { $Grid-Map: (); #if sgs-has($grid-key) { $Grid-Map: sgs-get($grid-key); } #else { $New-Map: sgs-set($grid-key, $Grid-Map) } $Add-Grid: add-grid($grid-definition, $Grid-Map); $HOLDER: sgs-set($grid-key, $Add-Grid); } #mixin add-gutter($gutter-definition, $gutter-key: 'gutters') { $Gutter-Map: (); #if sgs-has($gutter-key) { $Gutter-Map: sgs-get($gutter-key); } #else { $New-Map: sgs-set($gutter-key, $Gutter-Map) } $Add-Gutter: add-gutter($gutter-definition, $Gutter-Map); $HOLDER: sgs-set($gutter-key, $Add-Gutter); } #mixin add-gutter-style($gutter-style-definition, $gutter-style-key: 'gutter styles') { $Gutter-Style-Map: (); #if sgs-has($gutter-style-key) { $Gutter-Style-Map: sgs-get($gutter-style-key); } #else { $New-Map: sgs-set($gutter-style-key, $Gutter-Style-Map) } $Add-Gutter-Style: add-gutter-style($gutter-style-definition, $Gutter-Style-Map); $HOLDER: sgs-set($gutter-style-key, $Add-Gutter-Style); } Then I can define my grids like this... #include add-grid(2, 'copy grids'); #include add-grid(4 at $breakpoint-xs-min, 'copy grids'); #include add-grid(6 at $breakpoint-l-min, 'copy grids'); $copy-grids: sgs-get('copy grids'); #include add-gutter($gutter-width, 'copy gutters'); $copy-gutters: sgs-get('copy gutters'); #include add-grid(2, 'front grids'); #include add-grid(2 at $breakpoint-2up-min, 'front grids'); #include add-grid(3 at $breakpoint-3up-min, 'front grids'); #include add-grid(4 at $breakpoint-4up-min, 'front grids'); $front-grids: sgs-get('front grids'); #include add-gutter($front-gutter-width-em, 'front gutters'); $front-gutters: sgs-get('front gutters'); $front-gutter-styles: 'split' 'fixed'; ...giving me variables which I can pass into the layout function. Right now everything seems to be working, except for the gutter styles, which don't seem to have any effect on output, but that's a different issue.
Using multiple mixin's in one include in sass
Can multiple Mixin's be passed into an include in sass. example #mixin something{ //css declarations } #mixin somethingElse{ //css declarations } Can I do the following .class{ #include something,somethingElse; } or does it have to be .class{ #include something; #include somethingElse; }
Each mixin invocation requires an #include when using the scss syntax. If you were using the sass syntax instead, then you could save some keystrokes: =something //css declarations =somethingElse //css declarations .class +something +somethingElse
Changing from 4 to 3 columns with omega with Susy fails
This is certainly easiest to show with some code: .container{ .gallery { ul { #include clearfix; } li { #include span-columns(1,4); &:nth-child(4n) { #include omega; } } } #include at-breakpoint($large-columns) { .gallery { li { #include span-columns(1,3); &:nth-child(4n) { #include remove-omega; } &:nth-child(3n) { #include omega; } } } } } I'm starting out with 4 columns with the 4th being omega, then I want to change over to 3 columns, with the 3rd being omega. The correct elements are floated left/right correctly, but every 4th gets a wrong margin-right... Am I doing this right? Or rather, what am I doing wrong? Thanks for reading, /Andy
your question is misleading because we don't know the value of $large-columns. I assumed that value might be 59em 3 - but that works perfectly. It seems the value is actually just 59em - which is causing your problem. If you set a breakpoint without a column-count, Susy calculates a new context based on your $column-width and $gutter-width settings. That doesn't cause any problem for span-columns(1,3) because you override the global context with an explicit one (3). But remove-omega also needs to know the context (in order to apply gutters) and you don't pass one - so it uses the global context. You have two options: You can change the breakpoint: at-breakpoint(59em 3) You can pass an explicit context: remove-omega(3).