Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Dream4ever opened this issue Apr 5, 2022 · 0 comments
Closed

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

Dream4ever opened this issue Apr 5, 2022 · 0 comments
Labels
CSS The world is beautiful

Comments

@Dream4ever
Copy link
Owner

问题描述

一个页面里的图片在旧 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

@Dream4ever Dream4ever added the CSS The world is beautiful label Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS The world is beautiful
Projects
None yet
Development

No branches or pull requests

1 participant