移动端页面字体单位rem

来源:互联网 发布:linux 桌面 命令 编辑:程序博客网 时间:2024/05/22 16:08

1.rem根据页面大小来自适应

2.写入下面这段js

 function fontSize(){

var deviceWidth = $(document).width();
if(deviceWidth > 640){
    deviceWidth = 640;
    console.log(deviceWidth);
}
 
var fontSize = deviceWidth / 6.4;
$("html").css("fontSize",fontSize);
console.log(fontSize)
}
 
fontSize();
 
$(window).resize(function(){
    fontSize();

});

3.假如字体是12px。我们就写0.12rem,14==0.14rem,20==0.2rem,以此类推

4.这样在不同分辨率的手机上就会显示不一样的字体大小。

0 0
原创粉丝点击