Home  Web-development   Image objec ...

Image object-fit - cover and contain differences

The object-fit property in CSS is used to control how the content of a replaced element (like an image or video) fits into its container. The cover and contain values are two common options, and they have distinct behaviors:

object-fit: cover

img.cover {
  object-fit: cover;
  width: 100%;
  height: 100%;
}

object-fit: contain

img.contain {
  object-fit: contain;
  width: 100%;
  height: 100%;
}

Visual Comparison

Practical Use Cases

Published on: Jul 19, 2024, 10:36 AM  
 

Comments

Add your comment