移动端rem
手机有很多尺寸的型号。使用rem来做为大小单位可以达到兼容的目的。
方法一:js测量手机尺寸,设置font-size:为手机屏幕width /10 + ‘px’。即10rem 为手机屏幕width。
方法二:css的媒体查询,列举所要兼容的手机尺寸,按照方法一设置html的font-size。
代码:
方法一
(function () {
var newRem = function () {
html.style.fontSize = html.getBoundingClientRect().width / 10 + 'px'
}
window.addEventListener('resize', newRem, false)
newRem()
})()
方法二
。。。