postcss-pxtorem

postcss-pxtorem屏幕自适应

//安装插件
npm install postcss postcss-pxtorem --save-dev
//在根目录中新增postcss.config.cjs或postcss.config.js文件,并写上如下代码
module.exports = {
  plugins: {
    "postcss-pxtorem": {
      rootValue: 16,
      selectorBlackList: [],
      propList: ["*"]
    }
  }
};
//在工具文件夹新增文件tranfrom.ts设置缩放比例
 const baseSize = 16;
function tranfrom() {
  const scale = document.documentElement.clientWidth / 1920;
  document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + "px";
}

tranfrom();
window.onresize = function () {
  tranfrom();
};
//在main.ts文件中引入
import "@/utils/tranfrom";

设置完成后重启就可以了

https://www.cnblogs.com/dingxingxing/p/17664126.html
https://blog.csdn.net/weixin_44265146/article/details/131741369
https://blog.csdn.net/Bdbdbdnnd/article/details/132531925

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值