Customizing Bootstrap CSS template

前端 未结 9 1130
面向向阳花
面向向阳花 2020-11-22 09:03

I am just getting started with Bootstrap from Twitter and am wondering what the ‘best practices’ is for customization. I want to develop a system that will take advantage of

相关标签:
9条回答
  • 2020-11-22 09:54

    You can use the bootstrap template from

    http://www.initializr.com/

    which includes all the bootstrap .less files. You can then change variables / update the less files as you want and it will automatically compile the css. When deploying compile the less file to css.

    0 讨论(0)
  • 2020-11-22 09:58

    Since Pabluez's answer back in December, there is now a better way to customize Bootstrap.

    Use: Bootswatch to generate your bootstrap.css

    Bootswatch builds the normal Twitter Bootstrap from the latest version (whatever you install in the bootstrap directory), but also imports your customizations. This makes it easy to use the the latest version of Bootstrap, while maintaining custom CSS, without having to change anything about your HTML. You can simply sway boostrap.css files.

    0 讨论(0)
  • 2020-11-22 09:59

    I recently wrote a post about how I've been doing it at Udacity for the last couple years. This method has meant we've been able to update Bootstrap whenever we wanted to without having merge conflicts, thrown out work, etc. etc.

    The post goes more in depth with examples, but the basic idea is:

    • Keep a pristine copy of bootstrap and overwrite it externally.
    • Modify one file (bootstrap's variables.less) to include your own variables.
    • Make your site file @include bootstrap.less and then your overrides.

    This does mean using LESS, and compiling it down to CSS before shipping it to the client (client-side LESS if finicky, and I generally avoid it) but it is EXTREMELY good for maintainability/upgradability, and getting LESS compilation is really really easy. The linked github code has an example using grunt, but there are many ways to achieve this -- even GUIs if that's your thing.

    Using this solution, your example problem would look like:

    • Change the nav bar color with @navbar-inverse-bg in your variables.less (not bootstrap's)
    • Add your own nav bar styles to your bootstrap_overrides.less, overwriting anything you need to as you go.
    • Happiness.

    When it comes time to upgrade your bootstrap, you just swap out the pristine bootstrap copy and everything will still work (if bootstrap makes breaking changes, you'll need to update your overrides, but you'd have to do that anyway)

    Blog post with walk-through is here.

    Code example on github is here.

    0 讨论(0)
提交回复
热议问题