The first time when I know vh I was very excited. Finally, we can do this by css instead of js. However, still too naive.
As we all know, scroll bar would hide automatically on mobile. So, it wouldn"t affect the layout like on desktop.
However, the address bar would also hide when scrolling. Like images below:
And the code is:
Document
The viewport size changes when scrolling. In my Mi6X, the smaller is 659px while the larger one is 715px when the address bar is hidden.
According to test on chrome 70, height:100% and window.innerHeight is always equal to the smaller one. I think it is correct. I also thought 100vh would act like 100%. However, it"s not.
According to developers.google the vh is always calculated as if the URL bar is hidden since Chrome version 56.
So, 100vh is equal to the larger one which is 715px on my phone. That"s why images above would happen. In this case, if we use something like bottom:0; with 100vh we would meet situation like image one. Part of app__footer was covered. Instead, if we use height:100%, it won"t happen.
However, as we all know it wouldn"t be possible to use 100% when we were in nested css modules. So, in this case, how can we get the 100% in nested css modules?
Of course, we can save the 100% to rem like:
document.documentElement.style.fontSize = window.innerHeight * 0.01 + "px"
But I think the better way is using CSS_variables. For example:
html, body, .app { /* height: 100%; */ /* height: 100vh; */ height: calc(var(--vh) * 100); }
document.documentElement.style.setProperty( "--vh", window.innerHeight * 0.01 + "px" )
Also, if you are worried about the compatibility. Here is the polyfill.
Original Post
Referencethe-trick-to-viewport-units-on-mobile
CSS3 100vh not constant in mobile browser
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/114363.html
The first time when I know vh I was very excited. Finally, we can do this by css instead of js. However, still too naive. As we all know, scroll bar would hide automatically on mobile. So, it wouldnt ...
摘要:可以看到,雖然是同樣的請求數(shù)據(jù),在不同的階段和不同組件看來,是完全不同的形式。請求還有一個不那么明顯的特性它不能被應(yīng)用修改,應(yīng)用只能讀取請求的數(shù)據(jù)。 這是 flask 源碼解析系列文章的其中一篇,本系列所有文章列表: flask 源碼解析:簡介 flask 源碼解析:應(yīng)用啟動流程 flask 源碼解析:路由 flask 源碼解析:上下文 flask 源碼解析:請求 flask 源碼解...
摘要:執(zhí)行函數(shù)調(diào)用規(guī)范中的第一步是一個明顯的賦值語句,我們查看規(guī)范,賦值語句會發(fā)生什么可以看出簡單賦值語句返回的是對等于號右邊進(jìn)行之后的結(jié)果,上一節(jié)講了,執(zhí)行過就會返回的類型,此處會返回也就是一個類型。 前言 this是JavaScript中的著名月經(jīng)題,每隔一段時間就有人翻出了拿各種奇怪的問題出來討論,每次都會引發(fā)一堆口水之爭。從搜索引擎搜了一下現(xiàn)在的比較熱門的關(guān)于this的用法,如:Ja...
摘要:表達(dá)式的計算值和屬性的值與指定名稱的元素有關(guān)根據(jù)下面的規(guī)則在的表達(dá)總是返回一個字符串。在沒有命名空間這將只是一個標(biāo)識符。 本文不是w3c翻譯 保留原文的基礎(chǔ)上 做出自己的理解為主 參考 http://www.w3.org/TR/2015/CR-css-values-3-20150611/#attr-notation attr函數(shù)介紹 The attr() fun...
摘要:注意,下面一個立即執(zhí)行的函數(shù),周圍的括號不是必須的,因為函數(shù)已經(jīng)處在表達(dá)式的位置,解析器知道它處理的是在函數(shù)執(zhí)行階段應(yīng)該被創(chuàng)建的,這樣在函數(shù)創(chuàng)建后立即調(diào)用了函數(shù)。 本文是翻譯http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#introduction 概要In this article we will talk abou...
閱讀 3250·2019-08-30 15:55
閱讀 2973·2019-08-30 13:46
閱讀 1472·2019-08-29 17:29
閱讀 3542·2019-08-29 11:08
閱讀 3469·2019-08-29 11:04
閱讀 1111·2019-08-28 18:20
閱讀 565·2019-08-26 13:37
閱讀 1358·2019-08-26 11:49