gpt4 book ai didi

javascript - 如何让我的汉堡包菜单图标位于我的横幅图片之上?

转载 作者:行者123 更新时间:2023-11-30 09:25:19 26 4
gpt4 key购买 nike

我在将汉堡包图标置于横幅图片顶部时遇到了问题。我试过调整 z-index,将导航背景颜色设置为透明,并将背景图像放在标题而不是横幅部分。我不知道要采取什么其他步骤。任何建议将不胜感激。

function openNav() {
document.getElementById("main-nav").style.height = "100%";
}

function closeNav() {
document.getElementById("main-nav").style.height = "0%";
}
/*Nav*/
header {
background-color: transparent;
}

.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #567E3A;
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: #fff;
display: block;
transition: 0.3s;
}

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

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

.burger {
font-size: 2em;
cursor: pointer;
}



/*Banner*/

#banner {
background-image: url("http://res.cloudinary.com/dboauovcs/image/upload/c_scale,w_2000/v1521182602/camp3_xhp0d9.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
width: 100%;
display: grid;
}

.banner-text {
margin: auto;
text-align: center;
color: #fff;
}

.banner-text h1 {
margin: 2em 1.4em 1.4em 1.4em;
font-size: 2em;
line-height: 1.8;
color: #fff;
text-shadow: 3px 3px #000;
}
<header>
<nav id="main-nav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<div class="overlay-content">
<a href="#">Destinations</a>
<a href="#">Accomidation</a>
<a href="#">Stories</a>
<a href="#">Contact</a>
</div>
</nav>

<span class="burger" onclick="openNav()">&#9776;</span>
</header>



<section id="banner">
<div class="banner-text">
<h1>Lorem Lipsum</h1>
<a href="#" class="btn">Book Today</a>
</div>
</section>

最佳答案

像这样?

function openNav() {
document.getElementById("main-nav").style.height = "100%";
}

function closeNav() {
document.getElementById("main-nav").style.height = "0%";
}
/*Nav*/
header {
background-color: transparent;
}

.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #567E3A;
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: #fff;
display: block;
transition: 0.3s;
}

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

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

.burger {
font-size: 2em;
cursor: pointer;
position: absolute;
}



/*Banner*/

#banner {
background-image: url("http://res.cloudinary.com/dboauovcs/image/upload/c_scale,w_2000/v1521182602/camp3_xhp0d9.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
width: 100%;
display: grid;
}

.banner-text {
margin: auto;
text-align: center;
color: #fff;
}

.banner-text h1 {
margin: 2em 1.4em 1.4em 1.4em;
font-size: 2em;
line-height: 1.8;
color: #fff;
text-shadow: 3px 3px #000;
}
<header>
<nav id="main-nav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<div class="overlay-content">
<a href="#">Destinations</a>
<a href="#">Accomidation</a>
<a href="#">Stories</a>
<a href="#">Contact</a>
</div>
</nav>

<span class="burger" onclick="openNav()">&#9776;</span>
</header>



<section id="banner">
<div class="banner-text">
<h1>Lorem Lipsum</h1>
<a href="#" class="btn">Book Today</a>
</div>
</section>

关于我在这里所做的事情的一些解释(假设这是您正在寻找的治疗方法):positioning the hamburger as absolute ,我们将它完全拉出静态布局流,所以其他元素在定位时忽略它的存在。然后可以使用 left 控制元素的位置。 , right , topbottom , 并将相对于绝对定位的第一个祖先元素定位自身,如果没有绝对定位的元素,则相对于 body 。您可能需要考虑使用这些属性调整定位,因为您可能不希望依赖浏览器使用默认值计算其位置。

关于javascript - 如何让我的汉堡包菜单图标位于我的横幅图片之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49355778/

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