Customizing Bootstrap CSS template

前端 未结 9 1307
面向向阳花
面向向阳花 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: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.

提交回复
热议问题