I was wondering how to get the spacer variables generic with the use of Bootsrap in a custom class.
I have a class .box and want to apply the class pl-3 of bootstrap 4. I don't want to add the class inline in HTML but want to style it in sass.
I want to use the spacer variables of Bootstap and not hardcoded in the class itself. So if i want to change the padding in the future i only have to change the padding in the sass.
I have the following defined:
$spacer: 1rem !default;
$spacers: (
0: 0,
1: ($spacer * .125), // 2px
2: ($spacer * .25), // 4px
3: ($spacer * .375), // 6px
4: ($spacer * .5), // 8px
5: ($spacer * 0.75), // 12px
6: ($spacer * 1) // 16px
)
What is the best way to do this? What i have found out is this:
.box{
@extend .pl-3;
}
But i don't like it this way. It's not very self explaining Is there an other/ better way to do this? Like:
.box{
padding-left: $spacer-3;
}