We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postcss-pxtorem是用来自动将px单位转为rem单位,来实现不同端间的自适应的
安装依赖:
pnpm install postcss postcss-pxtorem -D
module.exports = { // ... module: { rules: [ { test: /\.(css|less)$/, use: [ 'style-loader', 'css-loader', { loader: 'postcss-loader', options: { postcssOptions: { plugins: [ require('postcss-pxtorem')({ rootValue: 75, propList: ['*'] }) ] } } } ] } ] } }
module.exports = { plugins: { 'postcss-pxtorem': { rootValue: 75, // 这个值是设计稿宽度的 1/10,如果你的设计稿宽度为750px,则rootValue应该设置为75 propList: ['*'], unitPrecision: 5, } } }
通过exclude属性来控制对指定文件进行编译
module.exports = { plugins: { 'postcss-pxtorem': { rootValue: 75, // 这个值是设计稿宽度的 1/10,如果你的设计稿宽度为750px,则rootValue应该设置为75 propList: ['*'], unitPrecision: 5, exclude: (file)=>{ // 只对src/styles下的样式文件进行编译 if (file.indexOf('src/styles') !== -1) return false; return true; } } } }
通过Px替换px,来避免rem的转换
Px
px
border: 1Px solid #ccc
The text was updated successfully, but these errors were encountered:
// 设置 rem 函数 function setRem() { // 设置页面根节点字体大小, 字体大小最小为12 document.documentElement.style.fontSize = (document.documentElement.clientWidth * 100) / 375 + 'px'; } //初始化 setRem(); //改变窗口大小时重新设置 rem,这里最好加上节流 window.onresize = function () { setRem(); }
Sorry, something went wrong.
No branches or pull requests
postcss-pxtorem
postcss-pxtorem是用来自动将px单位转为rem单位,来实现不同端间的自适应的
安装依赖:
几种常见的使用方式
webpack中配置
postcss.config.js中配置
可能遇到的问题
只想对指定的文件进行编译
通过exclude属性来控制对指定文件进行编译
有的样式不想进行px转rem
通过
Px
替换px
,来避免rem的转换The text was updated successfully, but these errors were encountered: