Execute the command to install the plugin postcss-pxtorem npm install postcss-pxtorem -D Create a new package.json in the same directory as postcss.config.js. The content of the file is as follows module.exports = { plugins: { 'autoprefixer': { browsers: ['Android >= 4.0', 'iOS >= 7'] }, 'postcss-pxtorem': { rootValue: 32, //The result is: design element size/32 (generally, the root element size of a 750px design is set to 32). For example, if the element width is 320px, the final page will be converted to 10rem propList: ['*'], //property selector, * indicates general selectorBlackList:[] ignores the selector.ig- indicates that all the selectors starting with .ig- will not be converted} } } After the configuration of postcss.config.js is completed, the project needs to be restarted to take effect Create a new rem.js file in the util directory in the root directory src. // rem proportional adaptation configuration file // Base size const baseSize = 750 // Note that this value must be consistent with the rootValue in the postcss.config.js file // Set rem function function setRem () { // The current page width is relative to the 375 width scaling ratio, which can be modified according to your needs. Generally, the design draft is 750 width (you can get the design drawing and modify it for convenience). const scale = document.documentElement.clientWidth / 375 // Set the font size of the root node of the page ("Math.min(scale, 2)" means the maximum magnification ratio is 2, which can be adjusted according to actual business needs) document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px' } // Initialize setRem() // Reset rem when changing window size window.onresize = function () { setRem() } Import the rem.js file into main.js and start the project The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Collection of 25 fonts used in famous website logos
>>: Detailed explanation of how to pass values between react hooks components (using ts)
Table of contents 1. What is Javascript? 2. What ...
1. Link layout of the new site homepage 1. The loc...
question Question 1: How to solve the performance...
The equal-width layout described in this article ...
Table of contents 1. Shallow cloning 2. Deep clon...
Table of contents Array deduplication 1. from() s...
This article shares with you how to install Kylin...
This article mainly discusses the differences bet...
Building web pages that comply with Web standards ...
Table of contents background Question 1 Error 2 E...
Table of contents Where are the logs stored? View...
Table of contents 1. Introduction to docker-maven...
Friends who have bought space and built websites s...
Table of contents Preface text 1. Concepts relate...
Table of contents docker system df docker system ...