移动端1px解决方案

移动端1px解决方案

设备像素比?

window.devicePixelRatio是设备上物理像素和设备独立像素(device-independent pixels (dips))的比例。

-webkit-min-device-pixel-ratio的常见值对照

-webkit-min-device-pixel-ratio为1.0

  1. 所有非Retina的Mac
  2. 所有非Retina的iOS设备
  3. Acer Iconia A500 
  4. Samsung Galaxy Tab 10.1
  5. Samsung Galaxy S 

-webkit-min-device-pixel-ratio为1.3

  1. Google Nexus 7

-webkit-min-device-pixel-ratio为1.5

  1. Google Nexus S 
  2. Samsung Galaxy S II 
  3. HTC Desire
  4. HTC Desire HD
  5. HTC Incredible S 
  6. HTC Velocity
  7. HTC Sensation

-webkit-min-device-pixel-ratio为2.0

  1. iPhone 4
  2. iPhone 4S
  3. iPhone 5
  4. iPad (3rd generation)
  5. iPad 4
  6. 所有Retina displays 的MAC
  7. Google Galaxy Nexus
  8. Google Nexus 4
  9. Google Nexus 10
  10. Samsung Galaxy S III
  11. Samsung Galaxy Note II
  12. Sony Xperia S
  13. HTC One X 

实现移动端1px边框有以下几种方式:

背景图渐变

背景图图片

js判定支持0.5px

rem解决方案

scale缩放的方式

背景图渐变

样例: 百度糯米

背景图图片

js判定支持0.5px

rem解决方案

样例: 美团

scale缩放的方式(推荐此方式)

整体实现DEMO

http://10.14.57.140:8022/demo.html

原文地址:https://www.cnblogs.com/fang51/p/5681528.html