scss和less px 转rem
时间:2017-07-12 21:31:48
收藏:0
阅读:1636
1 首先设置默认字符大小
<script> (function() { var html = document.documentElement; var hWidth = html.getBoundingClientRect().width;//根据屏宽调节大小 // console.log( hWidth ); html.style.fontSize = hWidth / 15 + "px";//设置默认字符大小 25 })() </script>
2 scss写法:
@function t($px) { @return $px / 50px * 1rem; } p { width: t(20px); }
3 less 写法:
@r:50rem;
p{
width: 20/@r;
}
4 编译后:
p { width: 0.4rem; }
评论(0)