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

前端 未结 8 1802
慢半拍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:31

    You can use jQuery in order to fix that.

    $('container').height($(window).height()/2);
    

    This works on every browser. Hope it helps.

    0 讨论(0)
  • 2020-12-14 17:31

    I found this library very useful: https://github.com/Hiswe/vh-check

    It will calculate the offset value for the correct vh, and put it in a css variable so you can use it in the css:

    .main {
      height: calc(100vh - var(--vh-offset, 0px));
    }
    
    0 讨论(0)
提交回复
热议问题