Bootstrap – Object Fit


Bootstrap – Object fit



”;


This chapter discusses about the object fit utilities. These utility classes are used to resize the content of the replaced elements, such as <img> or <video> to fit its container.

The object-fit property either preserves the aspect ratio or stretches to take up as much as space available of the content in the container.

The format of this property is .object-fit-{value}. Following are the values that .object-fit class takes up:

  • contain – The entire content will be scaled down or up to fit within the container, while maintaining its original aspect ratio.

  • cover – The content will be scaled to cover the entire container, potentially cropping parts of it. The aspect ratio will be maintained.

  • fill – This is the default value. The image or video will fill the entire container, possibly stretching or squishing its original aspect ratio.

  • scale (for scale down) – The content will be scaled down to fit within the container, but only if it would be scaled up by using the contain value. Otherwise, it behaves as none.

  • none – This does not bring any change in the display of the content.

Let us see an example for .object-fit: none: