vue cli3中使用postcss-pxtorem进行适配(亲测有效!)
温馨提示:对行内样式无效喔~下载依赖npm install postcss-pxtorem -Dpostcss.config.jsmodule.exports = {plugins: {// 兼容浏览器,添加前缀autoprefixer: {overrideBrowserslist: ["Android 4.1","iOS 7.1","Chrome > 31","ff > 3
·
温馨提示:对行内样式无效喔~
下载依赖
npm install postcss-pxtorem -D
新建一个rem.js的文件,在main.js中引用。
// 蓝湖上设计稿自定义为375px 测量值直接写入即可
(function() {
const baseSize = 16; // 32
function setRem() {
const scale = document.documentElement.clientWidth / 375; // 750
document.documentElement.style.fontSize =
baseSize * Math.min(scale, 2) + "px";
}
window.onresize = function() {
setRem();
};
})();
postcss.config.js
module.exports = {
plugins: {
// 兼容浏览器,添加前缀
autoprefixer: {
overrideBrowserslist: [
"Android 4.1",
"iOS 7.1",
"Chrome > 31",
"ff > 31",
"ie >= 8",
"last 10 versions", // 所有主流浏览器最近10版本用
],
grid: true,
},
"postcss-pxtorem": {
rootValue: 16, //结果为:设计稿元素尺寸/16,比如元素宽320px,最终页面会换算成 20rem
propList: ["*"], //是一个存储哪些将被转换的属性列表,这里设置为['*']全部,假设需要仅对边框进行设置,可以写['*', '!border*']
unitPrecision: 5, //保留rem小数点多少位
//selectorBlackList: ['.radius'], //则是一个对css选择器进行过滤的数组,比如你设置为['fs'],那例如fs-xl类名,里面有关px的样式将不被转换,这里也支持正则写法。
replace: true, //这个真不知到干嘛用的。有知道的告诉我一下
mediaQuery: false, //媒体查询( @media screen 之类的)中不生效
minPixelValue: 12, //px小于12的不会被转换
},
},
};
// 蓝湖上设计稿自定义为375px 测量值直接写入即可 若设计稿为750px 则rootValue: 32
更多推荐
已为社区贡献5条内容
所有评论(0)