标签:charset strong 更新 iphone x color dia mini utf-8 fit
废话不多说,直接上干货。本文主要解决如何通过媒体查询适配所有iphone刘海屏。
html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- viewport-fit 有3个值(contain,cover,auto),默认值是contain, 需要设置为 cover ,css里面的safe-area-inset-***(***代表left,right,top,bottom)才会生效 --> <meta name="viewport" content="viewport-fit=cover"> <title>兼容刘海屏写法</title> </head> <body> <div class="page-content"> <div class="page-content-inner"></div> </div> </body> </html>
关于上面提到的 viewport-fit 和 safe-area-inset 相关知识可访问:CSS 在全屏iphonex(刘海屏)中的适配
scss:
//2021/01/25号前所有有刘海屏的iphone尺寸变量
// iphone x/xs/11 pro
$device-x: "screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3)";
// iphone xr/11
$device-xr: "screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2)";
// iphone x/xs/11pro max
$device-xmax: "screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3)";
// iphone 12mini
$device-12mini: "screen and (device-width: 360px) and (device-height: 780px) and (-webkit-device-pixel-ratio: 3)";
// iphone 12/12pro
$device-12: "screen and (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3)";
// iphone 12pro max
$device-12promax: "screen and (device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3)";
参考文档:
iPhone所有手机型号屏幕尺寸(2020-11-11更新)
标签:charset strong 更新 iphone x color dia mini utf-8 fit
原文地址:https://www.cnblogs.com/sese/p/14327044.html