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