移动端rem设置字体

css中设置字体单位有三种:px,em,rem

px是绝对单位,用px设置字可以保证设置的精准度;

em比较繁琐,所以现在移动端的web流行使用rem作为字体相对单位;

rem是一种相对单位,相对于本页面的根字体大小而设置;通常用法:

html{

  font-size:62.5%;

}

设置跟字体为62.5%即网页的默认字体一般为16px,这样设置可以令1rem == 10px方便计算;

针对大小屏幕的适应问题可以通过媒体查询的方法重新设置跟字体大小适应不同大小的手机屏幕eg:

html{font-size:10px}
@media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}}
@media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}}
@media screen and (min-width:415px) and (max-width:639px){html{font-size:15px}}
@media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}}
@media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}}
@media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}}
@media screen and (min-width:800px){html{font-size:25px}}

posted @ 2016-10-17 14:45  文艺范儿m  阅读(2876)  评论(0编辑  收藏  举报