Last active
April 26, 2020 15:44
-
-
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
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
// _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