CSS3 Object-fit Detailed

Source: Internet
Author: User

Upload avatar when encountered the problem of Avatar deformation, and finally through the object-fit:cover perfect solution. This CSS property can achieve the best and most perfect center auto-cropped image.

Object-fit Understanding

CSS3 background-size appear earlier, you should know some of its supported values, in addition to the value, it also supports several keywords, such as: cover, contain and so on.

Object-fit is similar, but there are some differences, there are 5 values:

. fill {Object-fit:fill;}

. contain {object-fit:contain;}

. cover {object-fit:cover;}

. none {Object-fit:none;}

. scale-down {Object-fit:scale-down;}

The specific meanings of each attribute value are as follows (self-understanding of the vernacular, official interpretation See official website):

    • Fill: Chinese explanation "fill". The default value . The replacement content is stretched to fill the entire content box, not guaranteed to maintain the original proportions.
    • Contain: Chinese explanation "contains". Maintain the original size ratio. Ensure that the replacement content size must be placed inside the container. Therefore, this parameter may leave a blank inside the container.
    • Cover: Chinese interpretation "overwrite". Maintain the original size ratio. Ensure that the replacement content size must be larger than the container size, with at least one width and height consistent with the container. Therefore, this parameter may make the replacement content (slice) part of the area invisible.
    • None: Chinese interpretation "none". Maintain the original size ratio. Keep the original size of the replacement content at the same time.
    • Scale-down: Chinese explanation "reduced". It is as if none or contain is set in turn, and the result is a smaller size.

Object-fit Property Testing

Let's test the effect of each of the property values shown with the width:200px and width:200px set for each IMG tag, plus the different values of the Object-fit property set, as follows:

Object-fit compatibility

CSS3 Object-fit Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.