To position an object fit cover in CSS, you can use the following code:

.image {
  width: 100%;
  height: 300px; /* adjust height as needed */
  background-image: url('your-image.jpg');
  background-size: cover;
  background-position: center;
}

In this example, we have created a container with a class of .image and set the width to 100% and a fixed height of 300px. We then set the background image using the background-image property and set the background-size to cover to ensure the image covers the entire container. Finally, we set the background-position to center to horizontally and vertically center the image.

You can adjust the values for the height and background position to get the desired result


原文地址: https://www.cveoy.top/t/topic/eFAS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录