移動端web開發

Media Query(媒體查詢):css

@media 媒體類型 and (媒體特性) {
        /* css樣式 */      
}


媒體類型: screen, print...
媒體特性: max-width, max-height.

 

meta基礎知識html

H5頁面窗口自動調整到設備寬度spa

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

方式一: scala

經過css判斷移動端口大小code

        /* 當屏幕最大(或小於360px)就用下面的樣式 */

        /*
        @media screen and (max-width: 360px) and (min-width: 321px){
            html {
                font-size: 20px;
            }
        }

        @media screen and (max-width: 320px) {
            html {
                font-size: 24px;
            }
        }
        */

方式二:htm

經過js判斷端口blog

// 經過js獲取手機窗口寬度
        let htmlwidth = document.documentElement.clientWidth ||
                document.body.clientWidth;
        console.log(htmlwidth);

//    獲取視窗高度
        let htmlDom = document.getElementsByTagName('html')[0];

  // 設置文字
        htmlDom.style.fontSize = htmlwidth / 10 + 'px';

 

rem

rem 基準值計算rem

rem 數值計算與構建get

rem 與scss結合使用scss

rem 適配實戰

1rem  = 16px  = (html的font-size)
170/16 = 170px

 

1rem = 16px

10 = 160px

相關文章
相關標籤/搜索