移动端开发遇到的一些兼容性问题及其整理

浅浅的花香味﹌ 2023-05-22 14:28 67阅读 0赞

此博客仅为个人开发整理笔记。

  1. IOS手机测试时会发现加了margin-bottom的属性无效。解决:替换为padding-bottom或者放个空盒子有高度宽度占位即可。
  2. IOS手机的输入框出现未知的内阴影。解决:input: {-webkit-appearance: none;}
  3. 控制手机上方的标题:document.title;
  4. canvas画出来的内容模糊问题。解决:canvas问题解决
  5. 移动端1px问题【有些机型显示的边框实际比1px粗一些】:
    dpr(devicePixelRatio)
    dpr = 设备物理像素/设备独立像素
    什么是设备物理像素,什么是设备独立像素,这些都不重要(详细讲解参考https://www.zhangxinxu.com/wordpress/2012/08/window-devicepixelratio/),重要的是你需要知道:
    dpr = 设备实际显示的像素比/css像素比
    比如css像素为1,设备的dpr为2,那么屏幕上实际显示的像素就是css像素*dpr,也就是2px。
    其中dpr可以通过css或者js查询出来,知道了css像素与实际显示像素的缩放比,那么就可以利用transform: scale()对1px进行缩放。
    2.利用dpr适配1px
    知道了什么是dpr,那么如何让利用dpr来适配1px呢。
    css实现(以下边框为例):
    css中可以利用media查询dpr

解决代码:

  1. .scale-1px {
  2. position: relative;
  3. border: none; &:after {
  4. position: absolute;
  5. left: 0;
  6. bottom: 0;
  7. content: '';
  8. width: 100%;
  9. height: 1px;
  10. }
  11. }
  12. @media screen and (-webkit-min-device-pixel-ratio: 2) {
  13. .scale-1px:after {
  14. -webkit-transform: scaleY(0.5);
  15. transform: scaleY(0.5);
  16. }
  17. }
  18. @media screen and (-webkit-min-device-pixel-ratio: 3) {
  19. .scale-1px:after {
  20. -webkit-transform: scaleY(0.33);
  21. transform: scaleY(0.33);
  22. }
  23. }

发表评论

表情:
评论列表 (有 0 条评论,67人围观)

还没有评论,来说两句吧...

相关阅读