Skip to content

Instantly share code, notes, and snippets.

@bbashy bbashy/_utilities.scss
Last active May 12, 2016

Embed
What would you like to do?
Bootstrap v4 responsive margin, padding and alignment
@each $breakpoint in map-keys($grid-breakpoints) {
@include media-breakpoint-up($breakpoint) {
.text-left-#{$breakpoint}-up { text-align: left !important; }
.text-right-#{$breakpoint}-up { text-align: right !important; }
.text-center-#{$breakpoint}-up { text-align: center !important; }
@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);
.#{$abbrev}-a-#{$breakpoint}-up-#{$size} { #{$prop}: $length-y $length-x !important; } // a = All sides
.#{$abbrev}-t-#{$breakpoint}-up-#{$size} { #{$prop}-top: $length-y !important; }
.#{$abbrev}-r-#{$breakpoint}-up-#{$size} { #{$prop}-right: $length-x !important; }
.#{$abbrev}-b-#{$breakpoint}-up-#{$size} { #{$prop}-bottom: $length-y !important; }
.#{$abbrev}-l-#{$breakpoint}-up-#{$size} { #{$prop}-left: $length-x !important; }
// Axes
.#{$abbrev}-x-#{$breakpoint}-up-#{$size} {
#{$prop}-right: $length-x !important;
#{$prop}-left: $length-x !important;
}
.#{$abbrev}-y-#{$breakpoint}-up-#{$size} {
#{$prop}-top: $length-y !important;
#{$prop}-bottom: $length-y !important;
}
}
}
}
@include media-breakpoint-down($breakpoint) {
.text-left-#{$breakpoint}-down { text-align: left !important; }
.text-right-#{$breakpoint}-down { text-align: right !important; }
.text-center-#{$breakpoint}-down { text-align: center !important; }
@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);
.#{$abbrev}-a-#{$breakpoint}-down-#{$size} { #{$prop}: $length-y $length-x !important; } // a = All sides
.#{$abbrev}-t-#{$breakpoint}-down-#{$size} { #{$prop}-top: $length-y !important; }
.#{$abbrev}-r-#{$breakpoint}-down-#{$size} { #{$prop}-right: $length-x !important; }
.#{$abbrev}-b-#{$breakpoint}-down-#{$size} { #{$prop}-bottom: $length-y !important; }
.#{$abbrev}-l-#{$breakpoint}-down-#{$size} { #{$prop}-left: $length-x !important; }
// Axes
.#{$abbrev}-x-#{$breakpoint}-down-#{$size} {
#{$prop}-right: $length-x !important;
#{$prop}-left: $length-x !important;
}
.#{$abbrev}-y-#{$breakpoint}-down-#{$size} {
#{$prop}-top: $length-y !important;
#{$prop}-bottom: $length-y !important;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.