Auto Resize Image in CSS FlexBox Layout and keeping Aspect Ratio?

后端 未结 8 858
长情又很酷
长情又很酷 2020-12-12 12:34

I\'ve used the CSS flex box layout which appears as shown below:

\"enter

If t

8条回答
  •  长情又很酷
    2020-12-12 13:05

    You might want to try the very new and simple CSS3 feature:

    img { 
      object-fit: contain;
    }
    

    It preserves the picture ratio (as when you use the background-picture trick), and in my case worked nicely for the same issue.

    Be careful though, it is not supported by IE (see support details here).

提交回复
热议问题