Home  >  Article  >  Web Front-end  >  How to deal with css img distortion

How to deal with css img distortion

藏色散人
藏色散人Original
2021-09-13 11:34:414259browse

Solution to css img distortion: 1. Open the corresponding css file; 2. Retain the length and width of the original element content by setting "object-fit:none;".

How to deal with css img distortion

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

What to do if css img is distorted?

CSS style width: 100% image distortion

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

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

Solve the problem of picture 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 very easy It’s good to see the difference in clarity

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 image size, the image will be automatically cropped to the middle position

Related Expansion:

In 1990, Tim Berners-Lee and Robert Cailliau jointly invented the Web. In 1994, the Web really came out of the laboratory.

Since the invention of HTML, styles have existed in various forms. Different browsers combine their own style languages ​​to provide users with control over page effects. The original HTML contained only a few display attributes.

With the growth of HTML, in order to meet the requirements of page designers, HTML has added many display functions. But as these functions increase, HTML becomes more and more complex, and HTML pages become more and more bloated. So CSS was born.

Hakun Lee proposed the original proposal of CSS in 1994. At the time, Bert Bos was designing a browser called Argo, so they decided to design CSS together.

In fact, there were already some suggestions for unifying style sheet languages ​​in the Internet industry at that time, but CSS was the first style sheet language that contained the rich meaning of "cascading". In CSS, styles in one file can be inherited from other style sheets. The reader can use his or her own preferred style in some places and inherit or "cascade" the author's style in other places. This layered approach gives both authors and readers the flexibility to add their own designs and mix in what everyone likes.

Ha Kun first proposed CSS at a conference in Chicago in 1994. CSS was proposed again at the www network conference in 1995. Boss demonstrated an example of the Argo browser supporting CSS. , Haken also demonstrated support for CSS in the Arena browser.

In the same year, the W3C organization (World WideWeb Consortium) was established. All the creative members of CSS became the W3C working group and went all out to develop CSS standards. The development of cascading style sheets was finally on the right track. More and more members were involved, such as Thomas Reaxdon of Microsoft, whose efforts eventually led to support for the CSS standard in the Internet Explorer browser. Ha Kun, Persia and others are the main technical leaders of this project. At the end of 1996, the first draft of CSS was completed. In December of the same year, the first formal standard for Cascading Style Sheets (Cascading Style Sheets Level 1) was completed and became a recommended standard by w3c.

In early 1997, the W3C working group responsible for CSS began to discuss issues not covered in the first edition. The results of the discussions formed the second edition of the CSS specification published in May 1998.

Recommended learning: "css video tutorial"

The above is the detailed content of How to deal with css img distortion. 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