Home  >  Article  >  Web Front-end  >  What to do if html images are distorted

What to do if html images are distorted

藏色散人
藏色散人Original
2021-04-12 09:32:555506browse

html Solution to image distortion: First open the corresponding HTML file; then find the image introduced by HTML img; finally, add the "object-fit:none;" attribute to the img image to solve the image distortion problem. .

What to do if html images are distorted

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

CSS style width: 100% image distortion

The screen is 1920 pixels, set the width of img: 1920px fixed size, the image is not distorted, set width: 100% image distortion

img{
      display:block;  /*img图片比父元素高度小几个像素,设置为块元素,使得父子div高度一致*/
      width:100%;
}

Solve the problem of image distortion caused by setting width: 100% in order to make the picture adapt to the screen size

object-fit: none;    /*保留原有元素内容的长度和宽度*/

If the effect is not obvious, you can select a picture with text, which can be seen well There is a sharpness difference

img{
      width:100%;
      max-width:100%;
      object-fit:none;
}

But please note that after setting object-fit:none, when the screen size is smaller than the picture size, the picture will be automatically cropped to the middle position

[Recommended learning: HTML video tutorial

The above is the detailed content of What to do if html images are distorted. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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