gpt4 book ai didi

css - 修复了滚动时 div 在 flexbox 后面的问题

转载 作者:太空宇宙 更新时间:2023-11-04 00:46:42 25 4
gpt4 key购买 nike

我是“编程”网站的新手(只是为了好玩),遇到了一个我找不到解决方案的问题。

代码在最后还是codeopen/Tisire/pen/wLRvdR

菜单按钮应该是固定的,永不隐藏但是当向下滚动时,菜单按钮位于 flexbox 后面

我已经在这里发现了类似的问题,但没有适合我的有效解决方案……flex 和 position 似乎不是一个好的组合。

有人知道吗?

代码:

function openNav() {
document.getElementById("myNav").style.height = "100%";
}
function closeNav() {
document.getElementById("myNav").style.height = "0%";
}
/* Menu */
#topnav {
margin-left: auto;
margin-right: auto;
padding-left: 1em;
padding-right: 1em;
max-width: 70em;
}

#logo {
font-size:2em;
float:left;
padding-top: 0.5em;
}

#menubutton {
font-size:80px;
cursor:pointer;
position:fixed;
}

#menuright {
float: right;
padding-right:5em;
}

.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-y: hidden;
transition: 0.5s;
}

.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}

.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}

.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}

.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}

@media screen and (max-height: 450px) {
.overlay {overflow-y: auto;}
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}

/*Just to fill space...*/
.somespaceforthistest {
padding-top: 100px;
text-align: center;
}

/*The Flexbox*/
.flex-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
max-width: 80em;
margin-left: auto;
margin-right: auto;
}

.flex-container > div {
background-color: #f1f1f1;
width: 25em;
margin: 10px;
height: 25em;
position: relative;
}

img.flex {
height: 100%;
width: 100%;
}


<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<div class="overlay-content">
<a href="#">Just</a>
<a href="#">some</a>
<a href="#">random</a>
<a href="#">points</a>
</div>
</div>

<div id="topnav">
<div id="logo">MyLogo</div>
<div id="menuright">
<div id="menubutton" onclick="openNav()">&#9776;</div>
</div>
</div>

<div class="somespaceforthistest">
Just some Text to fill space...<br>
Just some Text to fill space...<br>
Just some Text to fill space...<br>
Just some Text to fill space...<br>
Just some Text to fill space...<br>
Just some Text to fill space...<br>
Just some Text to fill space...<br>
</div>

<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>

最佳答案

z-index: 1; 添加到您的 #menubutton

查看此 fiddle

关于css - 修复了滚动时 div 在 flexbox 后面的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56952069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com