使用 flexible.js + rem 製做蘇寧移動端首頁

1、技術選型

在這裏插入圖片描述

2、搭建相關文件夾

在這裏插入圖片描述

3、設置視口標籤以及引入初始化樣式文件和js文件

在這裏插入圖片描述

4、body 樣式

在這裏插入圖片描述

5、rem 適配方案二 body樣式修改

index.cssjavascript

body {
    min-width: 320px;
    max-width: 750px;
    /* flexible 給咱們劃分了 10 等份 */
    width: 10rem;
    margin: 0 auto;
    line-height: 1.5;
    font-family: Arial, Helvetica;
    background: #f2f2f2;
}

再也不須要common.js來作屏幕適配了css

6、VScode px轉換rem 插件 cssrem

在這裏插入圖片描述

6.1 安裝 cssrem

在這裏插入圖片描述

6.2 設置html 字體大小基準值

  1. ctrl + 逗號 打開設置
    在這裏插入圖片描述html

  2. 找到擴展中的 cssrem 插件 進入 Root Font Size 修改
    在這裏插入圖片描述java

  3. 修改完成後 重啓 VScode佈局

7、search-content佈局以及修改 flexble.js 默認html字體大小

index.html字體

<body>
    <!-- 頂部部分 -->
    <div class="search-content"></div>
</body>

index.cssflex

.search-content {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 10rem;
    height: 1.173333rem;
    background-color: #FFC001;
}

在這裏插入圖片描述

咱們發現,因爲 flexble.js中的影響,頁面的效果實際上是根據咱們當前屏幕的大小來斷定的,並非咱們想要的效果,因此咱們須要修改 flexble.js 默認html字體大小
若是咱們的屏幕超過了 750px 那麼咱們就按照 750設計稿來執行url

@media screen and (min-width: 750px) {
    html {
        font-size: 75px;
    }
}

咱們發現頁面仍是沒有達到咱們想要的效果,緣由是權重不夠
在這裏插入圖片描述
爲 html 的字體大小設置 !important插件

@media screen and (min-width: 750px) {
    html {
        font-size: 75px!important;
    }
}
.search-content {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 10rem;
    height: 1.173333rem;
    background-color: #FFC001;
}

在這裏插入圖片描述

8、search-content 內容製做

index.htmlssr

<body>
    <div class="search-content">
        <a href="#" class="classify"></a>
        <div class="search">
            <form action="">
                <input type="search" value="新人專享禮">
            </form>
        </div>
        <a href="#" class="login">登陸</a>
    </div>
</body>

index.css

a {
    text-decoration: none;
    font-size: .333333rem;
}
.classify {
    width: .586667rem;
    height: .933333rem;
    margin: .146667rem .333333rem .133333rem;
    background: url(../images/classify.png) no-repeat;
    background-size: .586667rem .933333rem;
}

.search {
    flex: 1;
}

.search input {
    outline: none;
    border: 0;
    width: 100%;
    height: .88rem;
    font-size: .333333rem;
    background-color: #FFF2CC;
    margin-top: .133333rem;
    border-radius: .44rem;
    color: #757575;
    padding-left: .733333rem;
}

.login {
    width: 1rem;
    height: .933333rem;
    margin: .133333rem;
    color: #fff;
    text-align: center;
    line-height: .933333rem;
    font-size: .333333rem;
}

在這裏插入圖片描述

相關文章
相關標籤/搜索