object-fit property in CSS

object-fit property in CSS

The object-fit CSS property sets how the content which includes images, videos and other embedded media formats should be resized to fit its container.

In the 👇 image, the object-fit property is applied to the lower row.

No alt text provided for this image

Let's get the ball rolling.

object-fit has one of these five values:

1. fill
2. contain
3. cover
4. none
5. scale-down        

In order to understand the above values one by one, we'll use the below code throughout the article:

<!DOCTYPE html
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img{
            height: 120px;
            width: 400px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <img src="cycling is meditation.jpg" alt="">
</body>
</html>>        


[Click to continue reading...]



To view or add a comment, sign in

More articles by Rajat Gupta

  • pseudo classes in css part 1 (:hover)

    Note: This is the first part of the series dedicated to the pseudo-classes of CSS. In this part, we'll understand the…

  • useContext in react: everything you need to know

    only understand this: Using useContext is not necessary, we use it to avoid prop drilling. Here's how prop drilling…

  • Sibling combinator in css

    There may be some confusion as what we are calling sibling. So, let's first get that out of the way.

  • rest parameter in javascript

    The rest parameter is introduced in ES6. It allows a function to accept an indefinite number of arguments as an array…

    1 Comment
  • PropTypes in react

    Let's see what reactjs.org has to say: As your app grows, you can catch a lot of bugs with type-checking.

  • What the heck are props in react

    Although we can make web apps using JavaScript. One of the reasons we are using react over JS is component reusability.

  • JavaScript: single-threaded and synchronous

    A few days ago single threaded and synchronous were just 2 heavy words for me. If this is you right now, don't worry…

    1 Comment
  • reduce() method in JavaScript

    Let's see what MDN has to say: The reduce() method executes a user-supplied “reducer” callback function on each element…

  • filter() method in JavaScript

    Definition by MDN: The filter() method creates a new array with all elements that pass the test implemented by the…

  • map() method in JavaScript

    Let's see what MDN has to say: The map() method creates a new array populated with the results of calling a provided…

Insights from the community

Others also viewed

Explore topics