咱們熟知的iPhone系列開發尺寸概要以下:javascript
△ iPhone各機型的開發尺寸css
轉化成咱們熟知的像素尺寸:html
△ 每一個機型的多維度尺寸java
倍圖其實就是像素尺寸和開發尺寸的倍率關係,但這只是外在的表現。倍圖核心的影響因素在於PPI(DPI),瞭解屏幕密度與各尺寸的關係有助於咱們深度理解倍率的概念:《基礎知識學起來!爲設計師量身打造的DPI指南》git
iPhone8在本次升級中,屏幕尺寸和分辨率都遺傳了iPhone6之後的優良傳統;github
然而iPhone X 不管是在屏幕尺寸、分辨率、甚至是形狀上都發生了較大的改變,下面以iPhone 8做爲參照物,看看到底iPhone X的適配咱們要怎麼考慮。web
咱們看看iPhone X尺寸上的變化:安全
蘋果對於 iPhone X 的設計佈局意見以下:iphone
核心內容應該處於 Safe area 確保不會被設備圓角(corners),傳感器外殼(sensor housing,齊劉海) 以及底部的 Home Indicator 遮擋。也就是說 咱們設計顯示的內容應該儘量的在安全區域內;ide
viewport-fit取值以下:
auto | 默認:viewprot-fit:contain;頁面內容顯示在safe area內 |
cover | viewport-fit:cover,頁面內容充滿屏幕 |
viewport-fit meta標籤設置(cover時)
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
如上圖所示 在iOS 11中的WebKit包含了一個新的CSS函數constant(),以及一組四個預約義的常量:safe-area-inset-left, safe-area-inset-right, safe-area-inset-top和 safe-area-inset-bottom。當合並一塊兒使用時,容許樣式引用每一個方面的安全區域的大小。
3.1當咱們設置viewport-fit:contain,也就是默認的時候時;設置safe-area-inset-left, safe-area-inset-right, safe-area-inset-top和 safe-area-inset-bottom等參數時不起做用的。
3.2當咱們設置viewport-fit:cover時:設置以下
body { padding-top: constant(safe-area-inset-top); //爲導航欄+狀態欄的高度 88px padding-left: constant(safe-area-inset-left); //若是未豎屏時爲0 padding-right: constant(safe-area-inset-right); //若是未豎屏時爲0 padding-bottom: constant(safe-area-inset-bottom);//爲底下圓弧的高度 34px }
viewport-fit:cover + 導航欄
注意這裏採用的是690px(safe area高度),不是812px;
@media only screen and (width: 375px) and (height: 690px){ body { background: blue; } }
1.關於iphoneX 頁面使用了漸變色時;若是viewport-fit:cover;
1.1在設置了背景色單色和漸變色的區別,若是是單色時會填充整個屏幕,若是設置了漸變色 那麼只會更加子元素的高度去渲染;並且頁面的高度只有690px高度,上面使用了padding-top:88px;
body固定爲:
<body><div class="content">this is subElement</div></body>
1.單色時:
* { padding: 0; margin: 0; } body { background:green; padding-top: constant(safe-area-inset-top); //88px /*padding-left: constant(safe-area-inset-left);*/ /*padding-right: constant(safe-area-inset-right);*/ /*padding-bottom: constant(safe-area-inset-bottom);*/ }
2.漸變色
* { padding: 0; margin: 0; } body { background:-webkit-gradient(linear, 0 0, 0 bottom, from(#ffd54f), to(#ffaa22)); padding-top: constant(safe-area-inset-top); //88px /*padding-left: constant(safe-area-inset-left);*/ /*padding-right: constant(safe-area-inset-right);*/ /*padding-bottom: constant(safe-area-inset-bottom);*/ }
解決使用漸變色 仍舊填充整個屏幕的方法;CSS設置以下
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1, viewport-fit=cover"> <title>Designing Websites for iPhone X: Respecting the safe areas</title> <style> * { padding: 0; margin: 0; } html, body { height: 100%; } body { padding-top: constant(safe-area-inset-top); padding-left: constant(safe-area-inset-left); padding-right: constant(safe-area-inset-right); padding-bottom: constant(safe-area-inset-bottom); } .content { background: -webkit-gradient(linear, 0 0, 0 bottom, from(#ffd54f), to(#ffaa22)); width: 100%; height: 724px; } </style> </head> <body> <div class="content">this is subElement</div> </body> </html>
2.頁面元素使用了固定定位的適配即:{position:fixed;}
2.1 子元素頁面固定在底部時;使用viewport-fit:contain時;能夠看到bottom:0時只會顯示在安全區域內;
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1"> <!--<meta name="viewport" content="initial-scale=1, viewport-fit=cover">--> <title>Designing Websites for iPhone X: Respecting the safe areas</title> <style> * { padding: 0; margin: 0; } /*html,body {*/ /*height: 100%;*/ /*}*/ body { background: grey; /*padding-top: constant(safe-area-inset-top);*/ /*padding-left: constant(safe-area-inset-left);*/ /*padding-right: constant(safe-area-inset-right);*/ /*padding-bottom: constant(safe-area-inset-bottom);*/ } .top { width: 100%; height: 44px; background: purple; } .bottom { position: fixed; bottom: 0; left: 0; right: 0; height: 44px; color: black; background: green; } </style> </head> <body> <div class="top">this is top</div> <div class="bottom">this is bottom</div> </body> </html>
2.1 子元素頁面固定在底部時;使用viewport-fit:cover時;能夠看到bottom:0時只會顯示在安全區域內;
* { padding: 0; margin: 0; } /*html,body {*/ /*height: 100%;*/ /*}*/ body { background: grey; padding-top: constant(safe-area-inset-top); /*padding-left: constant(safe-area-inset-left);*/ /*padding-right: constant(safe-area-inset-right);*/ /*padding-bottom: constant(safe-area-inset-bottom);*/ } .top { width: 100%; height: 44px; background: purple; } .bottom { position: fixed; bottom: 0; left: 0; right: 0; height: 44px; color: black; background: green; }
添加html,body {width:100%;heigth:100%}
圖1:
* { padding: 0; margin: 0; } html,body { height: 100%; } body { background: grey; padding-top: constant(safe-area-inset-top); padding-left: constant(safe-area-inset-left); padding-right: constant(safe-area-inset-right); padding-bottom: constant(safe-area-inset-bottom); } .top { width: 100%; height: 44px; background: purple; } .bottom { position: fixed; bottom: 0; left: 0; right: 0; height: 44px; color: black; background: green; }
圖2:
* { padding: 0; margin: 0; } html,body { height: 100%; } body { background: grey; padding-top: constant(safe-area-inset-top); padding-left: constant(safe-area-inset-left); padding-right: constant(safe-area-inset-right); /*padding-bottom: constant(safe-area-inset-bottom);*/ } .top { width: 100%; height: 44px; background: purple; } .bottom { position: fixed; bottom: 0; left: 0; right: 0; height: 44px; color: black; background: green; }
2.3 關於alertView彈框 遮罩層的解決方案
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <!--<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">--> <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <title>alertView</title> <script data-res="eebbk"> document.documentElement.style.fontSize = window.screen.width / 7.5 + 'px'; </script> <style> * { margin: 0; padding: 0; } html,body { width: 100%; height: 100%; } body { font-size: 0.32rem; padding-top: constant(safe-area-inset-top); padding-left: constant(safe-area-inset-left); padding-right: constant(safe-area-inset-right); padding-bottom: constant(safe-area-inset-bottom); } .content { text-align: center; } .testBut { margin: 50px auto; width: 100px; height: 44px; border: 1px solid darkgray; outline:none; user-select: none; background-color: yellow; } </style> <link href="alertView.css" rel="stylesheet" type="text/css"> </head> <body> <section class="content"> <button class="testBut" onclick="showLoading()">彈框加載</button> </section> <script type="text/javascript" src="alertView.js"></script> <script> function showLoading() { UIAlertView.show({ type:"input", title:"舒適提示", //標題 content:"VIP會員即將到期", //獲取新的 isKnow:false }); var xx = new UIAlertView(); console.log(xx); } </script> </body> </html>
參考資料: