web app iphone4 iphone5 iphone6 iphone6 Plus响应式布局 适配代码
2016-06-06 12:12
381 查看
在网页中,pixel与point比值称为device-pixel-ratio,普通设备都是1,iPhone 4是2,有些Android机型是1.5。]
那么-webkit-min-device-pixel-ratio:2可以用来区分iphone(4/4s/5)和其它的手机
iPhone4/4s的分辨率为640*960 pixels,DPI为是320*480,设备高度为480px
iPhone5的分辨率为640*1136 pixels,DPI依然是320*568,设备高度为568px
iPhone6的分辨率为750*1334 pixels,DPI依然是375*667,设备高度为667px
iPhone6 Plus的分辨率为1242x2208 pixels,DPI依然是414*736,设备高度为736px
那么我们只需要判断iphone手机的device-height(设备高)值即可区别iPhone4和iPhone5、iPhone6、iPhone6 Plus
使用css
通过 CSS3 的 Media Queries 特性,可以写出兼容iPhone4和iPhone5、iPhone6、iPhone6 Plus的代码~~
方式一,直接写到样式里面
方式二,链接到一个单独的样式表,把下面的代码放在<head>标签里
使用JS
那么-webkit-min-device-pixel-ratio:2可以用来区分iphone(4/4s/5)和其它的手机
iPhone4/4s的分辨率为640*960 pixels,DPI为是320*480,设备高度为480px
iPhone5的分辨率为640*1136 pixels,DPI依然是320*568,设备高度为568px
iPhone6的分辨率为750*1334 pixels,DPI依然是375*667,设备高度为667px
iPhone6 Plus的分辨率为1242x2208 pixels,DPI依然是414*736,设备高度为736px
那么我们只需要判断iphone手机的device-height(设备高)值即可区别iPhone4和iPhone5、iPhone6、iPhone6 Plus
使用css
通过 CSS3 的 Media Queries 特性,可以写出兼容iPhone4和iPhone5、iPhone6、iPhone6 Plus的代码~~
方式一,直接写到样式里面
@media (device-height:480px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone4/4s */ .class{} } @media (device-height:568px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone5 */ .class{} } @media (device-height:667px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 */ .class{} } @media (device-height:736px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 Plus */ .class{} }
方式二,链接到一个单独的样式表,把下面的代码放在<head>标签里
<link rel="stylesheet" media="(device-height: 480px) and (-webkit-min-device-pixel-ratio:2)" href="iphone4.css" /> <link rel="stylesheet" media="(device-height: 568px)and (-webkit-min-device-pixel-ratio:2)" href="iphone5.css" /> <link rel="stylesheet" media="(device-height: 667px)and (-webkit-min-device-pixel-ratio:2)" href="iphone6.css" /> <link rel="stylesheet" media="(device-height: 736px)and (-webkit-min-device-pixel-ratio:2)" href="iphone6p.css" />
使用JS
//通过高度来判断是否是iPhone 4还是iPhone 5或iPhone 6、iPhone6 Plus isPhone4inches = (window.screen.height==480); isPhone5inches = (window.screen.height==568); isPhone6inches = (window.screen.height==667); isPhone6pinches = (window.screen.height==736);
相关文章推荐
- 移动端页面监控input输入并且限制只输入2位小数
- @RequestMapping测试各种访问方式
- 添加删除表格append或 createElement
- Html5实现移动端、PC端 刮刮卡效果
- 微信开放平台开发——网页微信扫码登录(OAuth2.0)
- Android UI设计系列之自定义ListView仿QQ空间阻尼下拉刷新和渐变菜单栏效果(8)
- android 自定义Dialog去除黑色背景
- Xcode使用介绍之一:Xcode简介+创建App应用
- 小小站长成长记(3)--微信个人订阅号鸡肋之痛
- Android Studio 学习笔记 - 开发环境的架设
- Error ITMS-90635 invalid Mach-o format. the mach-o in hundle “*** ***.app/Frameworks/Result.framewor
- Android 事件分发细说
- android studio 更改背景和设置字体大小
- 用Android studio创建Cocos2d-x 3.X项目
- Unity_二维纹理 Texture 2D_4_总结细节
- 二维码登陆
- Android 崩溃日志 本地存储 与 远程保存
- Android自定义PopupWindow显示在控件上方或者下方
- Android UI设计系列之自定义Dialog实现各种风格的对话框效果(7)
- 【Android基础知识】ContentProvider(二)自定义ContentProvider和URI