When rotating an iPhone X to landscape, white space appears to the left and below cover image

为君一笑 提交于 2019-12-04 07:02:37

I found the solution and wanted to post it in case anyone else has this problem.

The iPhone X has the notorious notch and home bar. Apple doesn't want content to be covered by those items unless you explicitly tell it to. To achieve the desired result you can remove the whitespace by simply adding the following to your style declaration.

CSS:

html {
  // your css to create a cover image 
  padding: env(safe-area-inset); // <- this is the missing piece. Add it.
}

And updated the meta tag to include viewport-fit=cover

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">

The padding tells iPhone X to add the necessary padding so the actual content is not covered by the notch and home bar.

The viewport-fit=cover tells the browser to extend the viewport "under" the notch and home bar.

I hope this helps someone!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!