WebApp 使用post-css实现移动端适配

1、npm安装 post-css

npm i postcss autoprefixer postcss-pxtorem -D

2、新建配置文件 postcss.config.js

/* eslint-env node */

module.exports = {
  plugins: {
    autoprefixer: {
      overrideBrowserslist: ['Android >= 4.0', 'iOS >= 7']
    },
    'postcss-pxtorem': {
      // 根节点的 fontSize 值
      rootValue: 16,
      propList: ['*'],
      selectorBlackList: [':root']
    }
  }
}

3、 main.js中加入

// 实现不同设备的适配
const rootValue = 16     // 1rem
const rootWidth = 390    // 设计稿宽度
const deviceWidth = document.documentElement.clientWidth  //用户宽度
document.documentElement.style.fontSize = (deviceWidth * rootValue) / rootWidth + 'px'

相关推荐

  1. WebApp 使用post-css实现移动

    2024-05-16 06:12:08       18 阅读
  2. 移动方案

    2024-05-16 06:12:08       19 阅读
  3. vue开发的PC项目使用postcss-to-viewport移动

    2024-05-16 06:12:08       46 阅读
  4. vue pc-移动-ipad

    2024-05-16 06:12:08       45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-16 06:12:08       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-16 06:12:08       5 阅读
  3. 在Django里面运行非项目文件

    2024-05-16 06:12:08       4 阅读
  4. Python语言-面向对象

    2024-05-16 06:12:08       6 阅读

热门阅读

  1. 15. 三数之和

    2024-05-16 06:12:08       15 阅读
  2. docker版MySQL5.7重置root密码并授权localhost访问

    2024-05-16 06:12:08       13 阅读
  3. Qt初识

    Qt初识

    2024-05-16 06:12:08      16 阅读
  4. 时间格式数据向前或向后归于整时

    2024-05-16 06:12:08       16 阅读
  5. Zookeeper笔记,MIT6.824

    2024-05-16 06:12:08       18 阅读
  6. Go 语言将 PDF 转为 Word 如何处理

    2024-05-16 06:12:08       19 阅读
  7. hashmap数据结构为什么是链表

    2024-05-16 06:12:08       17 阅读