简体   繁体   中英

Issues with CSS position: fixed in iOS 9 iPhone 6+ in landscape mode

I found a weird issue with my fixed header under the following conditions:

  1. iphone 6+, landscape mode
  2. safari, at least two tabs opened
  3. my page has a position: fixed header and a body and html with position: relative, height: 100%

After page loads and when scrolling down, all works good, the header is in place and web inspector shows it correctly:

在此输入图像描述 在此输入图像描述

But when you scroll up and pull the page down the screen and release, the header is still visible on the page, but actually it is shifted somewhere below the viewport (see that web inspector does not highlight it).

在此输入图像描述

This fact results in all header elements being unaccessible: you cannot open the menu, click on the logo, or contact button.

The header goes back to normal when:

  1. you scroll down (but breaks again when you scroll back up)
  2. switch to another tab and back
  3. or close other tabs

I tried changing DOM or/and CSS of the header and body, but nothing puts the header back to normal state.

Any thoughts on how it can be fixed?

I am sorry to be the messenger of bad news, but I have no idea what your actual problem is since you posted no actual code. However, I would guess that since your problem is position:fixed , the best way to fix it is by stopping using position:fixed as it seems to not be working for you. Here is how you can equally-smoothly emulate it using only absolute and relative positioning:

 <html id="eHTML"> <style> #eHTML { position: static } #eBODY { position: relative; overflow:hidden } #eHTML, #eBODY, #main { width: 100%; height: 100%; margin: 0; top: 0 } #eBODY>div { position:absolute; left:0;bottom:0 } #footer {height: 20%;background-color:#88f;width:calc(100% - 14px)/*to account in for 14px scrollbar*/;overflow:hidden} #main {background-color:#ff8;width:100%;height:100%;overflow:auto} </style> <body id=eBODY> <div id=main> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p> <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,</p> <p>totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p> <p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p> <p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,</p> <p>sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</p> <p>Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?</p> <p>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur,</p> <p>vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p> <br /><br /><br /><br /> </div> <div id="footer"> Some Random Fixed<br /> Content! Yay, it workz! </div> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM