修复了标题在移动浏览器上的中断

时间:2019-10-22 13:19:20

标签: html css

我有一个固定的带有CSS的手机标头:

header {
position: fixed;
top: 0;
left: 0;
width: 40%;
height: 70px;
background: #191919;
z-index: 10;
-webkit-transform: translate3d(0,0,0);
padding-top: 10px;
}

这在大多数浏览器中都可以正常工作,但在三星浏览器中会被剪切或被状态栏隐藏,具体如下图所示

Mobile Header Capture

header {
  position: fixed;
  top: 0;
  left: 0;
  width: 40%;
  height: 70px;
  background: #191919;
  z-index: 10;
  -webkit-transform: translate3d(0, 0, 0);
  padding-top: 20px;
  width: 100%;
  color: white;
}

.content {
  background: red;
  position: relative;
  padding-top: 70px;
  width: 100%;
  height: 150vh;
}
<header class="myheader">My Header</header>

<div class="content">Some content</div>

2 个答案:

答案 0 :(得分:0)

您可能会受到新型移动设备的“缺口”功能的惩罚

请尝试设置viewport-fit=cover

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

其他可处理任何调整的属性:

  • 安全区域顶部
  • 安全区域插入权限
  • 安全区域插入左
  • 安全区域插入底部

参考:https://css-tricks.com/the-notch-and-css/

答案 1 :(得分:0)

这是一个简单的解决方案。我添加了溢出:滚动到#main { overflow: scroll;},保存标题和下面内容的div容器,此问题已解决。

相关问题