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 X 系列 #1

Open
JslinSir opened this issue Apr 25, 2022 · 1 comment
Open

小程序中 如何适配 IPhone X 系列 #1

JslinSir opened this issue Apr 25, 2022 · 1 comment
Labels
小程序 小程序开发相关

Comments

@JslinSir
Copy link
Owner

苹果 websites 设计规范

安全区示意图

329554c7855a238a

小程序中适配

padding-bottom: constant( safe-area-inset-bottom); /* 兼容 iOS < 11.2 */
padding-bottom: env( safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */

注意:env() 跟 constant() 需要同时存在,而且顺序不能换

使用 @supports 隔离兼容样式

@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
.iphone-x {
      padding-bottom: constant(safe-area-inset-bottom);
      padding-bottom: env(safe-area-inset-bottom);
   }
}

效果展示

WeChatefd0056ba6fd0feec80568f20a12a18c

同样也支持 calc 写法

非x 系列设备,距离底部距离

@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
.iphone-x {
      padding-bottom: calc(10rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(10rpx  + env(safe-area-inset-bottom));
   }
}
@JslinSir JslinSir added the 小程序 小程序开发相关 label Apr 25, 2022
@JslinSir
Copy link
Owner Author

H5 适配 IPhone X 系列

  • 在 meta 标签中增加 viewport-fit=cover
 <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,viewport-fit=cover" /> 
  • 设置body 安全区
 body {
  /* 适配齐刘海*/
  padding-top: constant(safe-area-inset-top);  
  padding-top: env(safe-area-inset-top);  
  /* 适配底部黑条*/
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
小程序 小程序开发相关
Projects
None yet
Development

No branches or pull requests

1 participant