自使用移动端rem适配--并且vscode-px自动转化成rem

来源:互联网 发布:网络流行语2017 编辑:程序博客网 时间:2024/05/20 16:13

1.在head标签中插入这个代码,表示根据屏幕宽度换算字体大小,刚开始设置根元素html的大小是20px

<title>健康记录</title>
<script>
window.onload=window.onresize =function(){
document.documentElement.style.fontSize =document.documentElement.clientWidth *20/320+'px';
};
</script>





2.安装vscode,然后在在扩展中输入 rem下载下面这个扩展


用法就是对你要改变的px按一下alt+z就行了

Keybindings

  • Alt+Z Px to rem, and rem to px. Converts selected text from px to rem, and rem to px.

.bbbb{
height:50px
}

按下alt+z之后呢就会变成


.bbbb{
height:3.125rem
}


3.更改配置文件,因为我们需要的是默认根元素是20px.而不是这个扩展默认设置的16px

a.我们在命令面板打开这个文件夹,然后输入

Extension



b.进入文件夹,然后找到你安装的这个扩展的.pa





c.重新启动vscode的扩展

原创粉丝点击