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

前端 未结 4 1797
萌比男神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条回答
  •  故里飘歌
    2021-02-02 09:59

    The accepted answer didn't work for me. I had to make two adjustments:

    • use document.body.style.height instead of document.body.height
    • add 'px' to the end of window.innerHeight

      document.body.style.height = ${window.innerHeight}px;

提交回复
热议问题