CSS 100vh is too tall on mobile due to browser UI

前端 未结 4 1796
萌比男神i
萌比男神i 2021-02-02 09:22

What is the best way to solve this issue. Obviously all browsers on mobile have got a UI (address bar etc) at the top. This adds additional height to the viewport, so my website

4条回答
  •  Happy的楠姐
    2021-02-02 09:54

    Use height: 100% which gives you the height after reducing the menu bar's height.

    You can test the difference between 100vh and 100% by using document.getElementsByTagName('html')[0].scrollHeight on mobile browser.

    For me (Chrome on Andriod), 100vh returns a higher value than 100%, which always giving me a vertical scrollbar, even if I haven't added anything in the html body.

提交回复
热议问题