Home > Web Front-end > CSS Tutorial > How to Achieve `object-fit: cover;` Image Scaling in IE and Edge?

How to Achieve `object-fit: cover;` Image Scaling in IE and Edge?

Barbara Streisand
Release: 2024-11-02 00:36:02
Original
975 people have browsed it

How to Achieve `object-fit: cover;` Image Scaling in IE and Edge?

CSS Fix for Image Scaling in IE and Edge

When using the object-fit: cover; CSS rule for images on a page, one might encounter an issue where the image resizes in width (not height) instead of zooming when scaling the browser in IE or Edge. This results in a distorted image.

To address this issue, a CSS solution can be implemented:

  1. Position the image absolutely within its container using the following code:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
Copy after login

This centers the image within its container.

  1. Based on the orientation of the image (vertical or horizontal), set the height and width properties accordingly:
  • For vertical blocks (height greater than width):

    height: 100%;
    width: auto;
    Copy after login
  • For horizontal blocks (width greater than height):

    height: auto;
    width: 100%;
    Copy after login

This gives the image the desired object-fit: cover; effect, ensuring it scales proportionally on resizing in IE and Edge.

The above is the detailed content of How to Achieve `object-fit: cover;` Image Scaling in IE and Edge?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template