Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to undertstand usage of $spacer in Bootstrap 4

Tags:

html

css

sass

I have a problem with understanding the $spacer variable(?) noted in Bootstrap 4's Spacing Documentation and couldn't find any documentation on it.

For example: 1 - (by default) for classes that set the margin or padding to $spacer * .25

.ml-1 {
  margin-left: ($spacer * .25) !important;
}

What I understand is the value of the variable is to be multiplied by 0.25, but how is that possible if the value is not even set?

like image 535
Baventhiran Avatar asked Feb 25 '18 08:02

Baventhiran


People also ask

What does $spacer mean in bootstrap?

$spacer is a SASS variable. By default it's value is 1rem . Therefore mt-1 is margin-top:. 25rem; The value for each of the 6 spacing units (0-5) are derived from the $spacers SASS map variable...

How do I give more margins in bootstrap?

Similarly, to add margin to an element, we can use the following margin classes: 'm-{size}' for all sides, 'mt-{size}' for top, 'mb-{size}' for bottom, 'ml-{size}' for left, 'mr-{size}' for right, 'mx-{size}' for horizontal and 'my-{size}' for vertical margins.

How do you put a space between two buttons using bootstrap in HTML?

Add an Empty div Element Between Two Buttons to Add Space Between Them in HTML. Use the margin-right Property to Put Space Between the Buttons in HTML.


2 Answers

If the variable wasn't set then it wouldn't be possible… but since it is set (right here), that doesn't matter.

like image 112
Quentin Avatar answered Nov 07 '22 19:11

Quentin


$spacer is a sass variable . its value is 16px in Bootstrap for example ml-1 mean margin-left with size 1 whose value is ($spacer * 0.25) i.e 16px*0.25 which is 1/4th value of 16px == 4px, therefore a size 1 for padding or margin stands for "$spacer * .25" :4px.
For size 2: $spacer * .5== 16px*0.5 == 8px. now..

size 3: $spacer*1 [the exact value] == 16px.
size 4: $spacer*1.5==24px.
size 5: $spacer*3 == 48px

like image 45
Afzal Ali s Avatar answered Nov 07 '22 20:11

Afzal Ali s