Retina显示优化

设备设备像素比所需图片
普通屏幕1x1倍基准尺寸
Retina(多数iPhone)2x2倍基准尺寸
Retina HD(iPhone Pro Max等)3x3倍基准尺寸
Android 高端机型2.5–3x推荐3倍
如果展示一张CSS尺寸为100×100px的图片,需准备200×200px(@2x)和300×300px(@3x)的版本。
<!-- 使用 srcset -->
<img src="image.jpg"
srcset="[email protected] 2x, [email protected] 3x"
width="200" height="200" alt="...">
<!-- 使用 picture 元素 -->
<picture>
<source srcset="[email protected] 2x" type="image/webp">
<img src="image.jpg" srcset="[email protected] 2x" alt="...">
</picture>
/* CSS 背景 Retina 适配 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
.logo { background-image: url('[email protected]'); background-size: 100px 50px; }
}