1. 程式人生 > >H5 font-size適配

H5 font-size適配

https://blog.csdn.net/highboys/article/details/78762744

方法一:

http://www.mamicode.com/info-detail-1816919.html

例如以螢幕320畫素為基準

html {font-size: 625%; /*100 ÷ 16 × 100% = 625%*/}

再用本工廠總結得出的各解析度媒體查詢換算:

@media screen and (min-width:360px) and (max-width:374px) and (orientation:portrait) {
    html { font-size: 703%; }
}
@media screen and (min-width:375px) and (max-width:383px) and (orientation:portrait) {
    html { font-size: 732.4%; }
}
@media screen and (min-width:384px) and (max-width:399px) and (orientation:portrait) {
    html { font-size: 750%; }
}
@media screen and (min-width:400px) and (max-width:413px) and (orientation:portrait) {
    html { font-size: 781.25%; }
}
@media screen and (min-width:414px) and (max-width:431px) and (orientation:portrait){
    html { font-size: 808.6%; }
}
@media screen and (min-width:432px) and (max-width:479px) and (orientation:portrait){
    html { font-size: 843.75%; }
}

至此,坑填完。設計稿px換算直接/100即可得到rem值。


方法二:

http://blog.csdn.net/sevenbblythelulu/article/details/45817227

1、許多方法測試所得(網上)

html {

    font-size: 62.5%;
}
@media only screen and (min-width: 481px){
    html {
        font-size: 94%!important;
    }
}
@media only screen and (min-width: 561px){
    html {
        font-size: 109%!important;
    }
}
@media only screen and (min-width: 641px){
    html {
        font-size: 125%!important;
    }

}

2、因為設計圖640px,手機裡就是320px,字型也小一半

html {
    font-size : 20px;
}
@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; 
    }
}

3、整理

 根元素16px,

html{font-size:62.5%;}  根元素改變為10px,320px(實際640px)

body{font-size:1.2rem;}   12px

@media only screen and (min-width:401px){       

 font-size:78%;

}  

401px  ---iPhone6plus  dpi

78%*16=12.48px

4、width:手機瀏覽器的解析度,而不是手機裝置的螢幕解析度

      Safari:320*480

      蘋果4:960*640

      米3:1080px  瀏覽器:360px

電腦端,瀏覽器解析度與電腦螢幕的解析度是一致的


方法三:

http://blog.csdn.net/naihejiang/article/details/59484556

css用@media適配不同尺寸的手機佈局方式

@media (device-height:568px)and (-webkit-min-device-pixel-ratio:2){/* 相容iphone5 */} @media only screenand (max-device-width :480px){ } @media only screen and (min-device-width :481px){ } /*6*/ @media (min-device-width : 375px)and (max-device-width : 667px)and (-webkit-min-device-pixel-ratio : 2){ } /*6+*/ @media (min-device-width : 414px)and (max-device-width : 736px)and (-webkit-min-device-pixel-ratio : 3){ } /*魅族*/ @media only screen and (min-device-width :1080px)and (-webkit-min-device-pixel-ratio : 2.5){ } /*mate7*/ @media only screen and (min-device-width :1080px)and (-webkit-min-device-pixel-ratio : 3){ } /*4 4s*/ @media only screen and (device-height :480px)and (-webkit-device-pixel-ratio:2){ }

第一種)常規適配方法:
1)html: 10px/16px=62.5% ------> 1rem  10px
2) 優化為 html:  100px/16px=625% ------> 1rem  100px
3) 0.01rem = 1px
4) xxx/100 = xxxx rem值


第二種)網易適配的方法:
1)750/20 = 37.5 px   ------> 1rem  37.5px
2)xxx/37.5 = xxxx rem值

https://www.cnblogs.com/lolDragon/p/7795174.html