bootstrap-sass

repository·master·Indexed 11 days ago

https://github.com/twbs/bootstrap-sass

A Sass-powered version of Bootstrap 3 (version 3.4.3) designed for integration into Sass-based applications via npm, Bower, or Ruby on Rails gems. It includes the full Bootstrap 3 framework with support for Sass variables, mixins, and JavaScript plugins such as Modals, Carousels, and Tooltips, requiring jQuery 1.9.1 up to (but not including) version 4.

Tokens
5.1K
Snippets
24
Records
31
Agent score
96%

What's inside bootstrap-sass

  1. Import Bootstrap fonts and path helpers

    master

    Bootstrap fonts are referenced using the pattern: "#{$icon-font-path}#{$icon-font-name}.eot".

    When using bootstrap-sass with Compass, Sprockets, or Mincer, you must import the relevant path helpers before importing Bootstrap itself:

    @import "bootstrap-compass";
    @import "bootstrap";
  2. Install bootstrap-sass in Ruby on Rails

    master

    To use bootstrap-sass in a Rails application with the asset pipeline, add the gem to your Gemfile and ensure sassc-rails is present.

    Steps:

    1. Update Gemfile:
      gem 'bootstrap-sass', '~> 3.4.1'
      gem 'sassc-rails', '>= 2.1.0'
    2. Run bundle install and restart your server.
    3. Import styles in app/assets/stylesheets/application.scss. Note: You must import bootstrap-sprockets before bootstrap for icon fonts to work.
      @import "bootstrap-sprockets";
      @import "bootstrap";
    4. Ensure your main stylesheet has a .scss or .sass extension. If it is .css, rename it and remove all *= require statements, replacing them with @import to ensure access to Bootstrap mixins and variables.
    5. For Bootstrap JavaScript, add jquery-rails to your Gemfile if using Rails 5.1+.
    6. Require JavaScript in app/assets/javascripts/application.js:
      //= require jquery
      //= require bootstrap-sprockets
      Warning: Do not include both bootstrap-sprockets and bootstrap in application.js.
    gem 'bootstrap-sass', '~> 3.4.1'
    gem 'sassc-rails', '>= 2.1.0'
  3. Configure Rails to use bootstrap-sass via Bower

    master

    If you are using the Bower version of bootstrap-sass within a Rails application, add the following configuration to config/application.rb to set up asset paths, precompile fonts, and set the required Sass number precision:

    # Bower asset paths
    root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
      config.sass.load_paths << bower_path
      config.assets.paths << bower_path
    end
    
    # Precompile Bootstrap fonts
    config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$
    
    # Minimum Sass number precision required by bootstrap-sass
    ::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max

    Then, update your imports:

    In application.scss:

    $icon-font-path: "bootstrap-sass/assets/fonts/bootstrap/";
    @import "bootstrap-sass/assets/stylesheets/bootstrap-sprockets";
    @import "bootstrap-sass/assets/stylesheets/bootstrap";

    In application.js:

    //= require bootstrap-sass/assets/javascripts/bootstrap-sprockets
    # Bower asset paths
    root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
      config.sass.load_paths << bower_path
      config.assets.paths << bower_path
    end
    # Precompile Bootstrap fonts
    config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$
    # Minimum Sass number precision required by bootstrap-sass
    ::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max
  4. Configure Sass number precision

    master

    bootstrap-sass requires a minimum Sass number precision of 8 (the default is often 5).

    If you are using the npm or Bower version with Ruby, you must set this manually:

    ::Sass::Script::Value::Number.precision = [8, ::Sas::Script::Value::Number.precision].max

    Note: When using the sassc-rails gem in Ruby, this is handled automatically.

    ::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max
  5. Configure Autoprefixer for Bootstrap compatibility

    master

    To match the browser compatibility of upstream Bootstrap, configure your Autoprefixer browsers option with the following list:

    [
      "Android 2.3",
      "Android >= 4",
      "Chrome >= 20",
      "Firefox >= 24",
      "Explorer >= 8",
      "iOS >= 6",
      "Opera >= 12",
      "Safari >= 6"
    ]
  6. Integrate bootstrap-sass with Ruby on Rails

    master

    The bootstrap-sass gem includes a Rails engine that automatically configures asset paths for stylesheets, javascripts, fonts, and images.

    If you are using an older version of sprockets-rails (version < 3), the engine manually adds a precompile rule for Glyphicons to ensure font assets are correctly processed: bootstrap/glyphicons-halflings-regular.(?:eot|svg|ttf|woff2?)$.

  7. Customize Bootstrap via Sass variables

    master

    You can override Bootstrap variables by redefining them before the @import directive.

    Example:

    $navbar-default-bg: #312312;
    $light-orange: #ff8c00;
    $navbar-default-color: $light-orange;
    
    @import "bootstrap";

    To perform a partial import (only specific components), copy the assets/stylesheets/_bootstrap.scss file to your assets as _bootstrap-custom.scss, comment out the components you don't want, and import that file instead:

    @import "bootstrap-custom";
  8. Use Bootstrap JavaScript modules

    master

    If you are using Sprockets or Mincer, you can load the full concatenated Bootstrap JavaScript file:

    //= require bootstrap-sprockets

    Alternatively, you can load individual modules to reduce file size, provided you also include their dependencies:

    //= require bootstrap/scrollspy
    //= require bootstrap/modal
    //= require bootstrap/dropdown
  9. Configure Tooltip options

    master

    The following options are available for the Tooltip component:

    OptionTypeDefaultDescription
    animationbooleantrueWhether to use CSS transitions
    placementstring/function'top'Where to position the tooltip
    selectorstringfalseSelector for delegated tooltips
    templatestring'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'The HTML template for the tooltip
    triggerstring'hover focus'Trigger(s) for showing the tooltip
    titlestring/function''The text or HTML to display
    delaynumber/object0Delay in ms (can be {show: n, hide: n})
    htmlbooleanfalseWhether to allow HTML in the title
    containerstring/jQueryfalseWhere to append the tooltip
    viewportobject{selector: 'body', padding: 0}The container for boundary detection
    sanitizebooleantrueWhether to sanitize HTML content
    sanitizeFnfunctionnullCustom sanitization function
    whiteListobjectDefaultWhitelistCustom whitelist for sanitization