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)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!