当我单击我的汉堡包图标时,会出现我的菜单,但它也将我跳到页面顶部。我想留在页面上的原处。我的标题是固定的,页面似乎在菜单显示之前就开始滚动。是否可以在不使用任何JavaScript的情况下解决此问题。如果我对此没事的话。
<header>
<div>
<img src="images/logo.png">
</div>
<input id="burger" type="checkbox" />
<label for="burger">
<span></span>
<span></span>
<span></span>
</label>
<nav>
<ul>
<li><a href="#">About Me</a></li>
<li><a href="#">Contact Me</a></li>
<li><a href="#">Link #3</a></li>
</ul>
</nav>
</header>
a {
text-decoration: none;
}
header img {
position: fixed;
top: 40px;
left: 40px;
z-index: 6;
width: 150px;
}
header input + label {
position: fixed;
top: 40px;
right: 40px;
height: 20px;
width: 15px;
z-index: 5;
}
header input + label span {
position: absolute;
width: 100%;
height: 2px;
top: 50%;
margin-top: -1px;
left: 0;
display: block;
background: #020304;
transition: 0.5s;
}
header input + label span:first-child {
top: 3px;
}
header input + label span:last-child {
top: 16px;
}
header label:hover {
cursor: pointer;
}
header input:checked + label span {
opacity: 0;
top: 50%;
}
header input:checked + label span:first-child {
opacity: 1;
transform: rotate(405deg);
}
header input:checked + label span:last-child {
opacity: 1;
transform: rotate(-405deg);
}
header input ~ nav {
background: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
z-index: 3;
transition: 0.5s;
transition-delay: 0.5s;
overflow: hidden;
}
header input ~ nav > ul {
text-align: center;
position: absolute;
top: 35%;
left: 20%;
right: 20%;
list-style-type: none;
}
header input ~ nav > ul > li {
opacity: 0;
transition: 0.5s;
transition-delay: 0s;
}
header input ~ nav > ul > li > a {
text-decoration: none;
text-transform: uppercase;
color: #020304;
font-weight: 700;
font-family: sans-serif;
display: block;
padding: 30px;
}
header input:checked ~ nav {
height: 100%;
transition-delay: 0s;
}
header input:checked ~ nav > ul > li {
opacity: 1;
transition-delay: 0.5s;
}
答案 0 :(得分:0)
只需更改href
属性:
<a href="javascript:;">About Me</a>