Skip to content

Instantly share code, notes, and snippets.

@krasenslavov
Last active April 26, 2020 15:44
Show Gist options
  • Save krasenslavov/1705be12acd7da0930639ea2641d781c to your computer and use it in GitHub Desktop.
Save krasenslavov/1705be12acd7da0930639ea2641d781c to your computer and use it in GitHub Desktop.
Sass mixin to customize object fit and position. Visit blog posts https://bit.ly/3bg4Rqs
// _object.scss
@mixin object($uid: object) {
$fit: (
'-contain': contain,
'-cover': cover,
'-fill': fill,
'-none': none,
'-scale-down': scale-down
);
@each $prop, $value in $fit {
.#{$uid}#{$prop} {
object-fit: $value;
}
}
$pos: (
'-top': top,
'-right': right,
'-bottom': bottom,
'-left': left,
'-center': center,
'-right-bottom': (right, bottom),
'-right-top': (right, top),
'-left-bottom': (left, bottom),
'-left-top': (left, top)
);
@each $prop, $value in $pos {
@if length($value) == 2 {
.#{$uid}#{$prop} {
object-position: #{nth($value, 1)} #{nth($value, 2)};
}
} @else {
.#{$uid}#{$prop} {
object-position: $value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment