在移动设备或 iPad 上将方向从纵向切换到横向时,网站两侧会出现空白

When switching orientation from portrait to landscape on a mobile device or iPad, white space appears on the sides of the website

提问人:NTM17 提问时间:10/23/2023 更新时间:10/23/2023 访问量:17

问:

因此,在移动设备上切换方向时(最大宽度为 540px)时,我遇到了空白问题。 当我的手机方向为纵向视图时,该网站看起来不错,但是当我翻转到横向时,两侧都有空白(见屏幕截图)。 我尝试使用媒体查询在方向为横向时将 margin: 0 添加到我的父容器 (.wrapper) 中,但这也没有解决它。有谁知道我可能做错了什么?

* {
  box-sizing: border-box;
}

html{
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
}

.wrapper{ /* My parent container */
  width: 100%;
  height: 100%;
  overflow: hidden;
}

@media (orientation: landscape) {
  .wrapper {
    margin: 0;
  }
}

Website on mobile device (portrait)

Website on mobile device (landscape)

HTML CSS ReactJS 媒体查询

评论


答:

0赞 Fabio Cazzavillan 10/23/2023 #1

这些空白在 ipad 上存在,因为 Apple 的“缺口”!

正如你在这里看到的:https://css-tricks.com/the-notch-and-css/ 苹果在他们的设备上出现缺口时,在网络上保留了一些安全区域。

为了避免这些,正如指南所建议的那样,您可以使用以下元:

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

评论

0赞 NTM17 10/24/2023
这真的很有帮助,已经解决了问题,非常感谢!