index.css
javascript
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
ctrl + 逗號
打開設置
html
找到擴展中的 cssrem 插件 進入 Root Font Size
修改
java
修改完成後 重啓 VScode佈局
index.html
字體
<body> <!-- 頂部部分 --> <div class="search-content"></div> </body>
index.css
flex
.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; }
index.html
ssr
<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; }