在PC上完成了我的导航栏,并将代码共享到我的iPhone上,以查看横向和纵向。在风景中,导航栏在右侧溢出。为非遮挡目的视图添加了 env(safe-area-inset) 值,但在右侧溢出。似乎找不到问题所在。
iPhone (11 Pro Max) Landscape Orientation左侧间隙是安全区env(),但右侧安全区间隙被导航栏溢出。
下面是一个例子:
@import url("https://fonts.googleapis.com/css2?family=Montserrat:ital@1&display=swap");
* {
box-sizing: border-box;
padding: 0;
margin: 0;
list-style: none;
text-decoration: none;
font-family: "Montserrat", sans-serif;
text-align: center;
}
body {
background: white;
padding-left: env(safe-area-inset-left);
padding-right: env(safe-area-inset-right);
padding-top: env(safe-area-inset-top);
}
.nav-bar {
display: flex;
justify-content: space-between;
padding: 0 2rem;
height: 50px;
align-items: center;
background: #0f0f0f;
color: #fff;
position: fixed;
top: 0;
width: 100%;
z-index: 999;
}
.hamburger {
display: none;
}
.hamburger i {
color: white;
font-size: 25px;
padding: 5px 7px;
border-radius: 5px;
}
.hamburger i:hover {
color: white;
background: rgb(69, 69, 69);
}
.nav-bar .nav-items {
display: flex;
margin-top: 4px;
align-items: center;
}
.nav-bar .nav-items li a {
user-select: none;
font-weight: bold;
display: block;
color: white;
font-size: 20px;
padding: 4px 10px;
transition: 150ms;
-webkit-transition: 150ms;
-moz-transition: 150ms;
margin: 0 10px;
}
.nav-bar .nav-items li a:after {
display: block;
content: "";
border-top: 2px solid rgb(140, 73, 255);
transform: scaleX(0);
-webkit-transform: scaleX(0);
-moz-transform: scaleX(0);
transition: transform 150ms ease-in-out;
-webkit-transition: transform 150ms ease-in-out;
-moz-transition: transform 150ms ease-in-out;
}
.nav-bar .nav-items li a:hover:after,
.nav-bar .nav-items li a.active:after {
transform: scaleX(1);
-webkit-transform: scaleX(1);
-moz-transform: scaleX(1);
}
.nav-bar .nav-items li a:hover {
filter: brightness(85%);
-webkit-filter: brightness(85%);
}
.nav-bar .login-register {
display: flex;
flex-direction: row;
}
.nav-bar .login-register .button {
user-select: none;
margin-bottom: 4px;
color: #fff;
font-size: 20px;
border: 2px solid rgb(116, 36, 255);
padding: 4px 20px;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
transition: all ease-in 0.2s;
-webkit-transition: all ease-in 0.2s;
-moz-transition: all ease-in 0.2s;
}
.nav-bar .login-register .button:hover {
background: rgb(116, 36, 255);
}
/*works fine | small res mobile view*/
@media only screen and (max-width: 850px) {
.hamburger {
height: auto;
display: block;
cursor: pointer;
}
.hamburger i {
width: 35px;
height: 35px;
background: #0f0f0f;
}
.nav-bar .nav-items {
flex-direction: column;
position: fixed;
width: 20vw;
background: #383838;
padding: 1.5rem 0;
height: 280px;
top: 46px;
z-index: 99;
right: -100%;
transition: 0.2s ease-in;
-webkit-transition: 0.2s ease-in;
-moz-transition: 0.2s ease-in;
}
.nav-bar .nav-items li a {
font-size: 20px;
padding: 0 10px;
margin: 10px 0;
}
.nav-bar .nav-items.active {
right: 0;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
<navbar class="nav-bar">
<div class="logo" onclick="window.location.href='Home.html'">TEST LOGO</div>
<div class="hamburger" for="check">
<i class="fa-solid fa-bars"></i>
</div>
<ul class="nav-items">
<li>
<a href="#" class="active">Home</a>
</li>
<li>
<a href="#">Explore</a>
</li>
<li>
<a href="#">Shop</a>
</li>
<li>
<a href="#">About</a>
</li>
<div class="login-register">
<a href="#" class="button">Login</a>
</div>
</ul>
</navbar>
我和一个朋友尝试了不同的改变,比如margin-padding,align-items,list-style,overflow,display,width/max-width属性。所有这些都导致导航栏内的内容移位或错误大小。
2条答案
按热度按时间e7arh2l61#
我试了你的代码,没有侧边栏出现
我建议你,如果你使用的是live服务器,刷新页面几次
rwqw0loc2#
我终于发现了导航栏溢出的问题,它应该是一个位置:sticky值。导航栏。