gpt4 book ai didi

html - 如何阻止我的移动菜单将我的网站向下移动?

转载 作者:行者123 更新时间:2023-11-28 05:46:09 25 4
gpt4 key购买 nike

我在移动设备上使用网站菜单时遇到问题。单击移动菜单时,下面的图像会随着菜单向下移动。无论如何我可以使用 z-indexs 将图像向后推并使移动菜单向前移动吗?

HTML:

    <header>
<ul class="topnav">
<li><a href="">Royal Navy</a></li>
<li><a href="">Home</a></li>
<li><a href="#news">About</a></li>
<li><a href="#contact">The Equpiment</a></li>
<li><a href="#about">Search</a></li>
<div class="search">
<input type="search" id="mySearch" value="">
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span> Search
</button>
</div>
<li class="icon">
<a href="javascript:void(0);" onclick="myFunction()">&#9776;</a>
</li>
</ul>

<div class="logo"><a href="">
<img border="0" alt="Royal Navy" src="/Volumes/NATHANSUSB/Programming/HTML/Royal Navy Website 2/Images/Logo.png" width="100px" height="119px">
</div>
</header>

<body>
<div class="img1">
<img alt="Made in the Royal Navy" src="/Volumes/NATHANSUSB/Programming/HTML/Royal Navy Website 2/Images/Made in the royal navy.jpg" width="100%" height="100%">
</div>
</body>

CSS:

.body{
background-color:#b5b5b5;
font-family: Arial, Helvetica, sans-serif;
margin:0;
}
.logo{
margin: -50px 0 -20px 10px;
position:absolute;
z-index:100;
}

ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

ul.topnav li {
float: left;
}

ul.topnav li a {
display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}

ul.topnav li a:hover {background-color: #4169e1;}

ul.topnav li.icon {display: none;}

.search{
margin: 14px 0px -20px 420px;
position:absolute;
z-index:100;
}

@media screen and (max-width:680px) {
ul.topnav li:not(:first-child) {display: none;}
ul.topnav li.icon {
float: right;
display: inline-block;
z-index:100;
}

.logo{
display:none;
}

.search{
display:none;
}

.img1{
z-index:-1;
}
}

@media screen and (max-width:680px) {
ul.topnav.responsive {position: relative;}
ul.topnav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.topnav.responsive li {
float: none;
display: inline;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
}

最佳答案

就像其他人在评论中所说的那样,内容被下推是因为它与通过单击导航栏切换的元素处于同一级别
一种解决方案是使导航栏的位置为固定绝对,并为正文提供等于导航栏高度的 padding-top 值,以便实际内​​容不会最终不会被它隐藏。

关于html - 如何阻止我的移动菜单将我的网站向下移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599645/

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