手动计算
<style>
body {
font-size: (16 / 37.5)rem;
}
#box {
width: (25 / 37.5)rem;
height: (25 / 37.5)5rem;
/*设计图的尺寸px / html的fontsize rem*/
background-color: antiquewhite;
}
</style>
less辅助计算
.pxToRem(@px) { //css混入
result: 1rem * (@px / 37.5); // 37.5这个值跟设计稿有关
}
.box {
width: .pxToRem(100)[result]; // [result]拿到值
height: .pxToRem(100)[result];
background-color: bisque;
}
p {
font-size: .pxToRem(14)[result];
}
pstcss-pxtorem(需要webpack配置)