Object-fit
Object-fit utilities for media elements with module mixins for responsive modifiers.
Utilities (anchor)
Utility name | Property values |
---|---|
Single element | |
.object-contain | object-fit: contain |
.object-cover | object-fit: cover |
.object-fill | object-fit: fill |
.object-scale-down | object-fit: scale-down |
.object-none | object-fit: none |
.object-initial | object-fit: initial |
Child element | |
.child-object-contain | object-fit: contain |
.child-object-cover | object-fit: cover |
.child-object-fill | object-fit: fill |
.child-object-scale-down | object-fit: scale-down |
.child-object-none | object-fit: none |
.child-object-initial | object-fit: initial |
Responsive mixins (anchor)
Responsive modifier mixins are provided to include where required in custom breakpoints, the utilities available use the following modifier class naming convention:
.object-cover
.object-cover-xxl
.object-cover-xl
.object-cover-lg
.object-cover-md
.object-cover-sm
.object-cover-xs
.object-cover-xxs
Using the module (anchor)
To use the module load the StyleMods scss
directory as follows (changing the path to suit the source files location as required) then include the Sass mixin anywhere below.
custom.scss
@use "stylemods/scss" as *;
@include object-fit-css;
// Example breakpoint
@media (width <= 480px) {
@include object-fit-sm-css;
}
Source code (anchor)
object-fit.scss
// ----------------------------------------------------------
// Object-fit
// ----------------------------------------------------------
$object-fit-values: (
"contain": contain,
"cover": cover,
"fill": fill,
"scale": scale-down,
"none": none,
"initial": initial,
) !default;
@mixin object-fit-css {
@each $name, $value in $object-fit-values {
.object-#{$name} {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name} * {
object-fit: $value;
}
}
}
@mixin object-fit-xxl-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-xxl {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-xxl * {
object-fit: $value;
}
}
}
@mixin object-fit-xl-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-xl {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-xl * {
object-fit: $value;
}
}
}
@mixin object-fit-lg-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-lg {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-lg * {
object-fit: $value;
}
}
}
@mixin object-fit-md-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-md {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-md * {
object-fit: $value;
}
}
}
@mixin object-fit-sm-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-sm {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-sm * {
object-fit: $value;
}
}
}
@mixin object-fit-xs-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-xs {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-xs * {
object-fit: $value;
}
}
}
@mixin object-fit-xxs-css {
@each $name, $value in $object-fit-values {
.object-#{$name}-xxs {
object-fit: $value;
}
}
@each $name, $value in $object-fit-values {
.child-object-#{$name}-xxs * {
object-fit: $value;
}
}
}