H5页面,移动端单位适配

js中script标签中直接写入:(网易写法)

document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px'即可;

这里的6.4写7.5也可,依据是设计图的尺寸是640的还是750的

页面的meta标签不需做任何处理即<meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">;

html和body标签也无需再指定font-size值;

但是页面文字大小如果需要精确设置需要额外的媒体查询;

更多可了解:

https://www.25xt.com/html5css3/16466.html

猜你喜欢

转载自blog.csdn.net/weixin_42315964/article/details/81409681