Docs feature: how to extends Bootstrap
It would be interesting to have a section thant explain how to extends and modifiy Bootstrap for our own project (jsute modify the .less file?) How that can work with the bootstrap update???
Thanks.
I second this request. Thank you!
I've been using this structure for my BootstrapBoilerplate (simplified):

I don't think changing core files of Bootstrap directly is the right way to go, because you loose the ability to update Bootstrap.
Instead i chose to put Bootstrap in an subfolder called lib. In my main folder there is a folder called css. Style.less is in most parts identitical to Bootstrap.less, it imports all the needed less files. The only difference is:
- additional variables.less included after bootstrap's responsive.less
- additional responsive.less included after bootstrap's responsive.less
- skin.less included at the end to change the look and feel
...
// Core variables and mixins
@import "../lib/bootstrap/lib/variables.less";
@import "variables.less";
...
// Skin
@import "skin.less";
// Responsive
@import "../lib/bootstrap/lib/responsive.less";
@import "responsive.less";
Here are some key points which makes this approach quite sensible in my opinion:
- easily maintainable and updatable
- full access to all of bootstraps mixins, variables and features
- resulting in 1 single css file
@mneuhaus I really like how you have bootstrap set up, +1 for coolness
We've been thinking about this a lot recently, and definitely realize we need to address it some capacity. One idea is to potentially pull in a second file, one ignored by the repo that anyone could add, to customize their variables before compiling? Perhaps a custom-variables.less might be useful in that regard.
Thoughts?
I agree on the custom-variables.less file, I'm already using one of those myself, added a specific line to Bootstrap for it.
I am modifying core bootstrap files to my own needs as I wish, 100% full control. I let GIT do the merging for me, and I don't even think about it.
I've tried extending it with separate files but I was modifying a lot of things and it was simply not effective, as I had to track CSS in both files, their and mine... oh this needs to be overridden too, oh crap and this too, oh crap I actually rewritten whole thing from scratch... and then bear in mind that your output CSS file grows in size unnecessarily (remember that LESS does not optimize it by removing duplicate declarations).
Right now with the 2.0 release I strongly believe it makes no sense to use separate files as all updates will be minor for a loooong time until 3.0 release. And these minor updates will smoothly merge in when you're doing proper updates via GIT.....And your project will be probably delivered to client by that time ;)
Besides, you're most probably want to customize many elements to suit your design, so why worry about original bootstrap things? If all your buttons need to have different font, padding, size, shadow, gradient, colors... why keep the original versions of CSS?
I use something similar @mneuhaus approach, without the boilerplate.
just a project.less which contains a copy of bootstrap.less in the top with modified paths, and an import to my own variables.less just after the import of bootstraps variables.less , though I just copied over the actuall variables Im using from bootstrap and put in some of my own which I use in project.less
Works well. Only issue I have is that links get the default bootstrap color if I include responsive.less in project.less since its re-importing variables.less so i just use the bundled bootstrap-responsive.css
Great minds think alike. I have a similar project, Kickstrap. Maybe we could collaborate?
Secretely I check Kickstrap's page every week to see the new design.
Ha. I think this will be the final one. What do you think?
Adam Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On jeudi, mars 22, 2012 at 5:53 PM, Maxime Fabre wrote:
Secretely I check Kickstrap's page every week to see the new design.
Reply to this email directly or view it on GitHub: https://github.com/twitter/bootstrap/issues/1451#issuecomment-4649264
+1 for having a way to inject own variables. humm at least in my setup i found out now it was responsive.less overriding my vars, the following works:
@import '../bootstrap/less/bootstrap.less';
@import 'myless.less';
@import '../bootstrap/less/responsive.less';
@import 'myvariables.less';
A way that allows one both
- Directly modify / contribute to bootstrap
- Mantain own codes to overwrite bootstrap (similar to @mneuhaus)
The solution is
- Fork bootstrap, say myBootstrap
- Make myBootstrap as a submodule in your own project via git submodule
- Add remote(the upstream repository i.e bootstrap) in the myBootstrap submodule folder. Then you can fetch bootstrap's update and merge to myBootstrap
There's also http://bootswatch.com/ themes and http://bootswatchr.com/ make-your-own themes available for anyone to use...
We've started this in 2.1.0-wip with an updated Extend page (and Getting Started page). If you have thoughts on how to expand on what we've added, I'd love to see more detailed issues or pull requests. Thanks!
Documenting this is a great idea, especially when I see so many people taking the TBS css files and editing them directly. When updates come out, they're out of luck.
The great thing about TBS, however, is it's for bootstrapping. So it's extendible but not meant to be a bloated download of all the cool stuff in the world you may or may not ever use.
As an easy way of extending bootstrap's source code I propose @tonyouyang solution via git submodule + less/custom/ folder
Ways it theoretically goes:
- custom/layout.less - for our 'main' custom layout
- custom/responsive-*.less - for each responsive version of layout
- custom/variables.less - for overriding and creating variables, we import it at the bottom of variables.less
Things to consider:
- is there any way to keep custom folder outside of source of bootstrap? - for now my only idea is symlink + .gitignore files from less/custom/ git submodule
- is there something like '@import-if-exists' in less or could be possibly written?
I tackled this problem in Kickstrap and after doing a lot of testing ended up doing the following (modified to incorporate @tonyouyang's solution:
/style.less
/custom/layout.less - for our 'main' custom layout /custom/responsive-*.less - for each responsive version of layout /custom/variables.less - for overriding and creating variables, we import it at the bottom of variables.less
/bootstrap/[bootstrap.less files]
Style.less will import all the necessary files in order. It's also important this is not at the same level of directory hierarchy as the custom and bootstrap files because it confuses some third party less processors which see @import statements everywhere.
It's also nice for using less.js client side (good for rapidly prototyping but that's another discussion), since you just import a single less file.
This is also a nice solution since some parts need to override, and others…underride? For example, layout.less should override bootstrap, but variables.less could change measurements in bootstrap.less. Since less only defines a variable once, once it's set in your custom variables file, it will override in the bootstrap variables file even though it's imported before.
If it were imported afterwards, it gets a little crazy--perhaps not working altogether unless you edit the bootstrap file to import your variables file…which defeats the purpose of leaving bootstrap alone.
Le lundi, août 27, 2012 à 10:03 AM, Leszek Piątek a écrit :
As an easy way of extending bootstrap's source code I propose @tonyouyang (https://github.com/tonyouyang) solution via git submodule (https://github.com/twitter/bootstrap/issues/1451#issuecomment-5978720) + less/custom/ folder (https://github.com/iRynek/bootstrap/commit/239790e2bb2ae62f4c76ba68de1fe2bb1e614a40) Ways it theoretically goes: custom/layout.less - for our 'main' custom layout custom/responsive-*.less - for each responsive version of layout custom/variables.less - for overriding and creating variables, we import it at the bottom of variables.less
Things to consider: is there any way to keep custom folder outside of source of bootstrap? - for now my only idea is symlink + .gitignore files from less/custom/ git submodule is there something like '@import-if-exists' in less or could by possibly written?
— Reply to this email directly or view it on GitHub (https://github.com/twitter/bootstrap/issues/1451#issuecomment-8056595).
Here's a possible example:
https://github.com/aguyawry/less_tests