移动端PSD设计稿与CSS的rem适配设置问题

rem 是 css3 中新增加的一个尺寸(度量)单位,根节点html的font-size决定了rem的尺寸,也就是说它是一个相对单位,相对于html

浏览器的默认的font-size是16px,1rem默认就等于16px。(chrome最小字体为12px)


注:7.2是指PSD设计稿宽度为(720/100)
如果PSD上测出字体大小或间距宽高为30px,则css上直接输出 0.3rem (30/100)

//设置全局字体
var n = function() {
	var n = document.documentElement.clientWidth;
	if(n > 414) {
		n = 414
	}
	document.documentElement.style.fontSize = n / 7.2 + "px";
};
window.onresize = function() {
	n();
};
n();
posted @ 2022-07-20 18:16  猫老板的豆  阅读(80)  评论(0编辑  收藏  举报