rem是什么?
rem(font size of the root element)是指相对于根元素的字体大小的单位
em与rem非常相似,只是单位计算所依赖的元素不一样
em(font size of the element)是指相对于父元素的字体大小的单位
作用:
rem能等比例适配所有屏幕
兼容性:
目前,IE9+,Firefox、Chrome、Safari、Opera 的主流版本都支持了rem。
兼容解决方案:
使用方法
rem是只相对于根元素htm的font-size,即只需要设置根元素的font-size
当html的font-size是10px时,1rem = 10px, 1.2rem = 12px …
html {
font-size : 10px;
}
@media only screen and (min-width: 401px){
html {
font-size: 25px !important;
}
}
@media only screen and (min-width: 428px){
html {
font-size: 26.75px !important;
}
}
@media only screen and (min-width: 481px){
html {
font-size: 30px !important;
}
}
@media only screen and (min-width: 569px){
html {
font-size: 35px !important;
}
}
@media only screen and (min-width: 641px){
html {
font-size: 40px !important;
}
}