1. Install postcss – pxtorem

npm install postcss-pxtorem -D
Copy the code

2. Create the postcss.config.js file in the root directory of the project

Module. exports = {plugins: {'autoprefixer': {}, 'postcss-pxtorem': {'rootValue': PropList: ['*']}}}Copy the code

3. Dynamically change the fontSize of the root element (uninstall main.js)

Function resizeCount() {const baseConstn = 192 // 1920 / base 10 const nowWidth = document.documentElement.clientWidth const nowCount = nowWidth / baseConstn Document.queryselector (' HTML ').style.fontsize = nowCount + 'px'} // Initialize resizeCount() windot.addeventListener ('resize',  () => { resizeCount() })Copy the code

4. Open the page and check whether the HTML elements change with the width of the window

5. Reference links

https://www.jianshu.com/p/8350b611e5bb
Copy the code