-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_custom.scss alternatives #22891
Comments
I always use my own css file loaded at the end to make customization, so it could be a _custom.css file suggested!? |
That's what I do too, but it results in duplicate/unneccesary rules from Bootstrap's style being left over in the resulting CSS. It'd be more efficient to override the variables before the scss is compiled. Meanwhile, I've found a workaround to get the old behaviour of $ cat _custom.scss _variables.scss > _variables_new.scss
$ mv -f _variables_new.scss _variables.scss |
@silverwind I think that we are supposed to use bootstrap through npm (or the like) and then include/compile the sass files using the facilities the bundler in question gives us. |
I haven't thought about importing it because most of my projects are pure CSS, so I can only use the compiled CSS for those. But yes, that would work for SCSS projects, which I coincidentally also have a few. So the gist is that CSS and preprocessors other than Sass are not supported for customization? Isn't that a bit opinionated? |
I've just decided on directly editing |
@rmoorman The two examples you provided don't work hardly at all anymore because of recent changes to the framework. As an example, say you want to change only the primary theme color. You'd want to create a custom SASS file that overrides the default value for the primary theme color and then imports the Bootstrap SASS file. However, the primary brand color is now defined as:
As far as I know you can't overwrite just the primary color by doing something like:
This would result in the other keys (e.g. warning, success) not being defined. If you copied the entire map and overwrite the primary key, you'd get errors because the variables such as Instead, what I am doing (and is the best I can come up with so far), is to copy the contents of
I think that is probably the best that can be done in order to leave the Bootstrap distribution unmodified but still allow you to customize the various aspects of the framework. Thoughts/suggestions? |
I assume bootstrap is expecting overrides BEFORE _variables.scss because The
Marking a variable with Because of this, I setup all custom variables on BEFORE/TOP of bootstrap and setup custom styles/mixin overrides on AFTER/BOTTOM of bootstrap:
(Note: You can also assign further custom variables on top (useful for white-labeling):
|
I do the same as @supergithubo and it works like a charm. (I tend not to save my custom-variables.scss in the same folder as the pulled/copied bootstrap folder). |
Be careful making a statement like that. It will make any previous assignment more important than the assignment using
I wouldn't say "expecting", but rather "supports". The
Example 1 is a plain example where the second declaration would override the first. Example 2 is from how Bootstrap used to support custom overrides by defining their values as defaults that only get set if no previous value was declared. Example 3 is how my setup works. Example 3 is effectively equivalent to example 1 since the So, while your suggestion/point does work for overriding Bootstrap's default values, it still has a major issue (in my opinion): In my previous comment I made a point about changing only the primary theme color, which using your method would result in having to copy the declarations for I DID, however, find a way where Bootstrap could provide its default map values and a developer could override specific keys in a file BEFORE the
The first line in the Bootstrap file, The second line declares Bootstrap's default map as the first input to map-merge which is then overridden by values in the If this change could be made to all maps in |
@os1r1s110
Agreed. The whole point of migrating away from |
@hokiecoder Do you think you could submit a PR to implement your map merge method by default? That's the behavior I expected. I am currently using the rubygem so I can't override the variables.scss file directly. |
@hokiecoder I used to set it up like yours but I ran into some problems with variable references inside
How did this worked for you:
In this example (defined in bootstrap), I want to change all whites from #fff to #f0f0f0 so I override it inside
Since
It seems your method only works on Did I miss something on your setup? |
@supergithubo couldn't you use your method (custom variables BEFORE variables) without copying the whole variables file? That's what I do and it seems to work really well (maybe I didn't have the complex use cases others had with mixins, etc...) I should add that I don't only have the "custom variables" file outside of the bootstrap imported folder, I also have my custom "boostrap-build.scss" which replaces the ones published with the distribution. This way I'm completely safe if my package manager updates bootstrap without me notifying it (except for variables/mixins that will have been removed, but that's my job to keep them synced at least for this). |
@os1r1s110 - Oh see. Thanks for pointing out. Say for example I want to change primary theme color from blue to green:
The problem is you need to redeclare |
True, there are pros and cons to any solution hehe :P But in my opinion, the drawbacks of copying the "general variables" as the colors, etc.. is not that bad to prevent me from doing it. So I will usually do so, copy all the variables that I need in my "custom-variables.scss" for it to work correctly and live with the fact that I might have a couple of duplicate lines (not in the final build though, only in build process, so not much of an issue in the end). As I said earlier though, my use case is pretty basic, I don't do anything really funky except modifying the colors, the number of grid breakpoints, some modifications here and there. But I don't really modify mixins etc... so that might be why I don't see much trouble in the solution I'm using right now, but I completely understand your point and I guess it will be everyone's choice to proceed as they see fits best. As for @hokiecoder 's idea, I find it pretty interesting, but I have no power whatsoever in bootstrap so we'll let the maintainers decide if they find it interesting enough to implement in the main distribution :) |
@supergithubo Thanks for pointing that out! I hadn't tested with a variable that had been re-used within the |
PR opened for @hokiecoder's suggestion at #23260. Please let me know if I've missed anything or need to take something else into consideration. I'm thinking no matter what this will wait for beta 2 as I don't see it as any kind of breaking change, just a bit of a weird one for some folks. 😅 |
This new color override is working pretty well for me, so I guess all that's left here to do it documentation. The $ cat _custom.scss _variables.scss > _variables_new.scss
$ mv -f _variables_new.scss _variables.scss
// start bootstrap's build process |
First of all, i am a beginner in using bootstrap, and having difficulties in understanding the explanation on: If this comment should be separate or belongs to another thread, just move it. As i understand it is like this: in custom.scss i could write: `// Your variable overrides // Bootstrap and its default variables First:
and a file _constants.scss that would contain things like:
Then it would be possible to do: `// Bootstraps constants first // Your variable overrides // Bootstrap and its default variables Second: The bootstrap theming url states you have to create your own "custom.scss". |
@mother10 Your |
@mdo Thanks for the quick answer. |
As I see it now, after many years of working with the v3 LESS implementation (where it wasn't even an issue), in order to reference an existing variable from // _my-bootstrap.scss
/*
* Bootstrap v4.0.0-beta.2
*/
@import '~bootstrap/scss/functions';
@import '~bootstrap/scss/variables';
@import 'custom-variables';
@import '~bootstrap/scss/mixins';
@import '~bootstrap/scss/root';
@import '~bootstrap/scss/print';
... The problem here is that after every update you'll have to compare the LESS has a notion of lazy variable evaluation which was weird back in the day but then you kinda used to it and use this approach everywhere and now it makes it hard to port LESS stylesheets to SCSS. I'm kinda OK with the new approach. We are heading towards PostCSS (remember that old 2015 tweet from @mdo). And that's great! But for now I have a proposal to split the @import "~bootstrap/scss/bootstrap-required";
@import "custom-variables";
@import "~bootstrap/scss/bootstrap-optional"; |
@pribilinskiy :) :) Happy user overhere. |
I might be wrong but sofar i dont see _variables.scss being split. So how does that solve the gray_900 problem i described? |
Now that
_custom.scss
has been remove in #22821, I wonder how builds with custom colors and the likes could be made. My build so far wastwbs/bootstrap
to a temporary location_custom.scss
into thescss
directoryThe PR mentions it was nuked "in favor of relying on imports from package manager directories" but I have a hard time following? Anyone care to explain?
The text was updated successfully, but these errors were encountered: