-
-
Save benjaminv/7bba5896a90ff3932bf02230abd3aa85 to your computer and use it in GitHub Desktop.
Backport Bootstrap 4 spacing classes to Bootstrap 3 SASS/SCSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//== Spacing | |
// | |
$grid-breakpoints: ( | |
xs: 0, | |
sm: $screen-sm-min, | |
md: $screen-md-min, | |
lg: $screen-lg-min | |
); | |
$spacer-x-0: 0rem; | |
$spacer-y-0: 0rem; | |
$spacer-x-1: .25rem; | |
$spacer-y-1: .25rem; | |
$spacer-x-2: .5rem; | |
$spacer-y-2: .5rem; | |
$spacer-x-3: 1rem; | |
$spacer-y-3: 1rem; | |
$spacer-x-4: 1.5rem; | |
$spacer-y-4: 1.5rem; | |
$spacer-x-5: 3rem; | |
$spacer-y-5: 3rem; | |
$spacers: ( | |
0: ( | |
x: $spacer-x-0, | |
y: $spacer-y-0 | |
), | |
1: ( | |
x: $spacer-x-1, | |
y: $spacer-y-1 | |
), | |
2: ( | |
x: $spacer-x-2, | |
y: $spacer-y-2 | |
), | |
3: ( | |
x: $spacer-x-3, | |
y: $spacer-y-3 | |
), | |
4: ( | |
x: $spacer-x-4, | |
y: $spacer-y-4 | |
), | |
5: ( | |
x: $spacer-x-5, | |
y: $spacer-y-5 | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/entozoon/spacing-bootstrap-3 (original credit - experimetal repo) | |
// | |
// Porting from Bootstrap 4 | |
// **************************** Ported mixins ******************************** | |
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) { | |
$min: map-get($breakpoints, $name); | |
@return if($min != 0, $min, null); | |
} | |
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { | |
$min: breakpoint-min($name, $breakpoints); | |
@if $min { | |
@media (min-width: $min) { | |
@content; | |
} | |
} @else { | |
@content; | |
} | |
} | |
// | |
// ****************************** _spacing.scss ****************************** | |
// https://github.com/twbs/bootstrap/blob/v4-dev/scss/utilities/_spacing.scss | |
// Width and height | |
.w-100 { width: 100% !important; } | |
.h-100 { height: 100% !important; } | |
.mw-100 { max-width: 100% !important; } | |
.mh-100 { max-height: 100% !important; } | |
// Margin and Padding | |
.mx-auto { | |
margin-right: auto !important; | |
margin-left: auto !important; | |
} | |
@each $breakpoint in map-keys($grid-breakpoints) { | |
@each $prop, $abbrev in (margin: m, padding: p) { | |
@each $size, $lengths in $spacers { | |
$length-x: map-get($lengths, x); | |
$length-y: map-get($lengths, y); | |
@include media-breakpoint-up($breakpoint) { | |
$min: breakpoint-min($breakpoint, $grid-breakpoints); | |
@if $min { | |
// everything else | |
.#{$abbrev}-#{$breakpoint}-#{$size} { #{$prop}: $length-y $length-x !important; } | |
.#{$abbrev}t-#{$breakpoint}-#{$size} { #{$prop}-top: $length-y !important; } | |
.#{$abbrev}r-#{$breakpoint}-#{$size} { #{$prop}-right: $length-x !important; } | |
.#{$abbrev}b-#{$breakpoint}-#{$size} { #{$prop}-bottom: $length-y !important; } | |
.#{$abbrev}l-#{$breakpoint}-#{$size} { #{$prop}-left: $length-x !important; } | |
.#{$abbrev}x-#{$breakpoint}-#{$size} { | |
#{$prop}-right: $length-x !important; | |
#{$prop}-left: $length-x !important; | |
} | |
.#{$abbrev}y-#{$breakpoint}-#{$size} { | |
#{$prop}-top: $length-y !important; | |
#{$prop}-bottom: $length-y !important; | |
} | |
} @else { | |
// xs | |
.#{$abbrev}-#{$size} { #{$prop}: $length-y $length-x !important; } | |
.#{$abbrev}t-#{$size} { #{$prop}-top: $length-y !important; } | |
.#{$abbrev}r-#{$size} { #{$prop}-right: $length-x !important; } | |
.#{$abbrev}b-#{$size} { #{$prop}-bottom: $length-y !important; } | |
.#{$abbrev}l-#{$size} { #{$prop}-left: $length-x !important; } | |
.#{$abbrev}x-#{$size} { | |
#{$prop}-right: $length-x !important; | |
#{$prop}-left: $length-x !important; | |
} | |
.#{$abbrev}y-#{$size} { | |
#{$prop}-top: $length-y !important; | |
#{$prop}-bottom: $length-y !important; | |
} | |
} | |
} | |
} | |
} | |
} | |
// Positioning | |
.pos-f-t { | |
position: fixed; | |
top: 0; | |
right: 0; | |
left: 0; | |
z-index: $zindex-navbar-fixed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment