Skip to content
0

Object Fit & Position ​

Control how a replaced element (<img>, <video>, etc.) fills its container and where it is positioned.

Object Fit ​

ClassProperties
.object-containobject-fit: contain
.object-coverobject-fit: cover
.object-fillobject-fit: fill
.object-noneobject-fit: none
.object-scale-downobject-fit: scale-down

Object Position ​

ClassProperties
.object-top-leftobject-position: top left
.object-topobject-position: top
.object-top-rightobject-position: top right
.object-leftobject-position: left
.object-centerobject-position: center
.object-rightobject-position: right
.object-bottom-leftobject-position: bottom left
.object-bottomobject-position: bottom
.object-bottom-rightobject-position: bottom right

Basic Usage ​

html
<!-- Cover the container, cropping if needed -->
<img class="object-cover w-full h-64" src="photo.jpg" alt="..." />

<!-- Contain within the container -->
<img class="object-contain w-48 h-48" src="logo.svg" alt="..." />

<!-- Position the image at the top -->
<img class="object-cover object-top w-full h-64" src="..." alt="..." />

SCSS Source ​

scss
// From _utilities.scss
$object-fit-list: (contain, cover, fill, none, scale-down) !default;

$object-position-map: (
  "top-left": top left, "top": top, "top-right": top right,
  "left": left, "center": center, "right": right,
  "bottom-left": bottom left, "bottom": bottom, "bottom-right": bottom right
) !default;

Released under the MIT License.