PC端网站 rem适配方案

以1920设计稿为准
1、使用sass语法 转换px rem , vscode编辑器安装插件easy-scss
安装之后打开插件setting.json, 在setting.json里配置转换后css的路径 “easysass.targetDir”: “./css”
在这里插入图片描述
创建css文件、scss文件:
在这里插入图片描述
项目中如何使用index.scss文件:
$yellow: yellow;
$theme: blue;
$orange: orange;
$red: red;

// PX 转 rem
@function px2Rem($px, KaTeX parse error: Expected '}', got 'EOF' at end of input: … @if (unitless(px)) {
//有无单位
@return (KaTeX parse error: Expected 'EOF', got '}' at position 24: …2) * 1rem; }̲ @else if (unit…px) == em) {
@return KaTeX parse error: Expected 'EOF', got '}' at position 9: px; }̲ @return (px / $base-font-size) * 1rem;
}

.nav p{
font-size: px2Rem(12px);
color: $red;
}

easy-scss 自动编译后的index.css:
.nav p {
font-size: 0.66667rem;
color: red;
}

2、设置媒体查询
@media screen and (max-width: 1920px) {
html {
font-size: 19.2px;
}
}
@media screen and (max-width: 1680px) {
html {
font-size: 16.8px;
}
}
@media screen and (max-width: 1380px) {
html {
font-size: 14.4px;
}
}
@media screen and (max-width: 1300px) {
html {
font-size: 12.8px;
}
}

3、代码热更新插件:Liver Serve (写完后页面会自动更新,不用再刷新了)
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值