monks/object_fit

The object-fit CSS property sets how the content of a {{ glossary(“replaced elements”, “replaced element”)}}, such as an {{HTMLElement(“img”)}} or {{HTMLElement(“video”)}}, should be resized to fit its container.

The object-fit property has no effect on {{HTMLElement(“iframe”)}}, {{HTMLElement(“embed”)}}, and {{HTMLElement(“fencedframe”)}} elements.

You can alter the alignment of the replaced element’s content object within the element’s box using the {{cssxref(“object-position”)}} property.

Values

pub const contain: #(String, String)
  • : The replaced content is scaled to maintain its {{glossary(“aspect ratio”)}} while fitting within the element’s content box. The entire object is made to fill the box, while preserving its aspect ratio, so the object will be “letterboxed” or “pillarboxed” if its aspect ratio does not match the aspect ratio of the box.
pub const cover: #(String, String)
  • : The replaced content is sized to maintain its aspect ratio while filling the element’s entire content box. If the object’s aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.
pub const fill: #(String, String)
  • : The replaced content is sized to fill the element’s content box. The entire object will completely fill the box. If the object’s {{glossary(“aspect ratio”)}} does not match the aspect ratio of its box, then the object will be stretched to fit.
pub const inherit: #(String, String)
pub const initial: #(String, String)
pub const none: #(String, String)
  • : The replaced content is not resized.
pub fn raw(value: String) -> #(String, String)

Enter a raw string value for object-fit

pub const revert: #(String, String)
pub const revert_layer: #(String, String)
pub const scale_down: #(String, String)
  • : The content is sized as if none or contain were specified, whichever would result in a smaller concrete object size.
pub const unset: #(String, String)
pub fn var(variable: String) -> #(String, String)

Enter a variable name to be used for object-fit. It will be wrapped in var() and have -- prepended.

Search Document