【css】移动端rem开发 多机型(分辨率)适配 根大小font-size

常用机型(分辨率)rem适配

常用机型分辨率

机型手机分辨率屏幕尺寸ppi/dpidpr
iphone5640*11364.02
iphone6750*13344.73252
iphone6plus1242*22085.53

参考链接: 分辨率,PPi,DPI,DPR,物理像素,逻辑像素

更多: iPhone 各尺寸手机分辨率

常用机型rem适配

// 适配不同屏宽
@media screen and (max-width: 10px)
    html {
		font-size: 10px !important;
	}

@media screen and (min-width: 10px) and (max-width: 320px)
    html {
		font-size: 10px !important;
	}
	
@media screen and (min-width: 321px) and (max-width: 375px)
    html {
		font-size: 13px !important;
	}

@media screen and (min-width: 376px) and (max-width: 435px)
    html {
		font-size: 14px !important;
	}

@media screen and (min-width: 436px) and (max-width: 600px)
    html {
		font-size: 15px !important;
	}

@media screen and (min-width: 601px) and (max-width: 700px)
    html {
		font-size: 16px !important;
	}
	
@media screen and (min-width: 701px) and (max-width: 1080px)
    html {
		font-size: 17px !important;
	}

@media screen and (min-width: 1081px)
    html {
		font-size: 18px !important;
	}

用法示例

2倍图UI

// rem适配:字号16px
.title {
	font-size: (16/13)rem;
}

// rem适配:宽30px  高30px  上边距8px
.content {
	margin-top: (8/13)rem;
	width: (30/13)rem;
	height: (30/13)rem;
}    

为了减少计算,可以使用css预处理器(如stylus)封装一下

// px转化为rem
pxToRem(val)
    (val / 13)rem
// rem适配:字号 16px
.title
	font-size pxToRem(16)
	
// rem适配:宽 30px; 高30px; 上边距 8px
.content 
	margin-top pxToRem(8)
	width pxToRem(30)
	height pxToRem(30)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值