How to fix vh(viewport unit) css in mobile Safari?

前端 未结 8 1830
慢半拍i
慢半拍i 2020-12-14 16:54

I\'ve used vh (viewport units) css in one of my projects but in mobile safari it doesn\'t work. It seems like Safari doesn\'t know what to do with vh, but it works fine in o

8条回答
  •  盖世英雄少女心
    2020-12-14 17:13

    I also had this issue, here is my solution.

    This is equals to height:100vh;

    document.getElementById("your-element").style.height = window.innerHeight + 'px';
    

    You can also use below code with jQuery,

    $('your-element').height(window.innerHeight + 'px');
    

    Checked with safari :)

提交回复
热议问题