wumi_blog icon indicating copy to clipboard operation
wumi_blog copied to clipboard

px em和rem等

Open 5Mi opened this issue 8 years ago • 0 comments

页面中body的默认font-size 一般为16px; 那么 1.4rem = (16 * 1.4 )px

但一般我们使用“1em”等于“10px”来改变默认值“1em=16px”,这样一来,我们设置字体大小相当于“14px”时,只需要将其值设置为“1.4em”。所以需要设置

body {
                font-size: 62.5%;/*10 ÷ 16 × 100% = 62.5%*/ /*font-size设为10px*/
            }

那么在sass中我们可以有如下mixin

//字体大小
@mixin fontSize($size:14){
    font-size:#{$size/10}rem;   /*默认1.4rem = 1.4 *10 px */
}

5Mi avatar Jun 02 '16 01:06 5Mi