Skip to content

旧 iPhone 上图片被纵向拉得很长 #185

@Dream4ever

Description

@Dream4ever

问题描述

一个页面里的图片在旧 iPhone 上被拉得很长,出现该情况的机型为 iPhone 7 及 iPhone XR,效果如下图所示。

9ed3b0eeb8b0355719bcfac21a848a9

解决过程

ios css parent inline-flex child image ratiocss ios image keep ratio 这两组关键字搜到的文章都没能解决问题,能够解决问题的 CSS force image resize and keep aspect ratio 又忘了是从哪里搜到的了,最终生效的是这个问答中的下面这段代码:

.img {
   object-fit: contain;
   max-width: 100%;
   max-height: 100%;
   width: auto;
   height: auto;
}

代码的变化如下图所示,猜测可能跟父元素的 flex 属性有关。

c20eee567ffbb322b8aaf038957c6cc

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSThe world is beautiful

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions