Prevent fixed-position background-image: cover from resizing in mobile browsers upon address bar hide

前端 未结 6 1698
北海茫月
北海茫月 2020-12-29 05:25

Sorry for a lack of example on this one, but I figure it\'s easy enough to understand.

I have a fixed background on my site, which is currently implemented like this

6条回答
  •  渐次进展
    2020-12-29 05:39

    For those still looking around for an answer, you can use the new vw and vh attributes with an element that is position: fixed.

    This scrolls while the address bar moves/shrinks/etc., then remains fixed on the page.

    #bgimg {
      display: block;
      background: no-repeat url(bg.png);
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 120vh;
    }
    

提交回复
热议问题