Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend Bootstrap 4.1 $spacers with additional sizes

The Bootstrap 4.1 documentation on spacing says that I can extend the $spacers variable (which is used by the margin and padding classes) but it doesn't explain how.

Can anyone share a link to official documentation? If that doesn't exist can anyone explain?

like image 921
Spencer Hill Avatar asked Aug 30 '18 21:08

Spencer Hill


1 Answers

You can follow Bootstrap's Variable defaults documentation for how to override the default for just a single Sass variable. You can add your own by setting $spacers in your override file:

// Your variable overrides
$spacer: 1rem;
$spacers: (
  6: ($spacer * 3.5),
  7: ($spacer * 10)
)

// Bootstrap and its default variables
@import "../node_modules/bootstrap/scss/bootstrap";

The variable the docs refer to is called $spacers and is in _variables.scss:

// Spacing
//
// Control the default styling of most Bootstrap elements by modifying these
// variables. Mostly focused on spacing.
// You can add more entries to the $spacers map, should you need more variation.

$spacer: 1rem !default;
$spacers: () !default;
// stylelint-disable-next-line scss/dollar-variable-default
$spacers: map-merge(
  (
    0: 0,
    1: ($spacer * .25),
    2: ($spacer * .5),
    3: $spacer,
    4: ($spacer * 1.5),
    5: ($spacer * 3)
  ),
  $spacers
);
like image 153
Ross Allen Avatar answered Sep 23 '22 22:09

Ross Allen