position: fixed doesn't work on iPad and iPhone

后端 未结 15 2138
一整个雨季
一整个雨季 2020-11-22 16:16

I have been struggling with fixed positioning in iPad for a while. I know iScroll and it does not always seem to work (even in their demo). I also know that Sencha has a fix

15条回答
  •  清歌不尽
    2020-11-22 16:39

    here is my solution to this...

    CSS

    #bgimg_top {
        background: url(images/bg.jpg) no-repeat 50% 0%; 
        position: fixed; 
        top:0; 
        left: 0; 
        right:0 ; 
        bottom:0;
    }
    

    HTML

    
    
    ....

    Explanation is that position fixed for the div will keep the div on the background at all time, then we stretch the div to go on all corners of the browser (provided the body margin = 0) using the (left,right,top,bottom) simultaneously.

    Please make sure you do not use the width and height as this will override the top,left,right,bottom options.

提交回复
热议问题