【发布时间】:2019-10-25 09:54:23
【问题描述】:
我一直在尝试让我的导航栏在滚动时固定在顶部。但它仍然固定在初始位置,而不会移动到停止位置并按我的意愿固定。代码如下,
我已经尝试过 W3 School 教程、引导和实现。但似乎没有任何帮助。这是我最后的选择。
div.wrapper {
font-family: Comic Sans MS;
width: 50%;
padding-right: 25%;
padding-left: 25%;
text-align: justify;
}
.topnav {
overflow: hidden;
background-color: #80F;
border-radius: 0%;
position: fixed;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #6900c4;
color: white;
}
.active {
background-color: #490089;
color: white;
}
.topnav .icon {
display: none;
}
<!-- The NAV BAR IS BELOW THE LOGO -->
<!--LOGO-->
<center>
<a target="_blank" href="https://www.englishessays.online"><img src="img/logoheader.png" alt="Logo" width="65%"></a>
</center>
<br>
<hr class="line" color="black">
<br>
<!--NAV-->
<div class="topnav" id="myTopnav">
<a href="https://www.englishessays.online">Home</a>
<a target="_blank" href="https://www.englishessays.online/essays.php" class="active">Essays</a>
<a target="_blank" href="www.englishessays.online/dialogues.php">Dialogues</a>
<a target="_blank" href="www.englishessays.online/speeches.php">Speeches</a>
<a target="_blank" href="www.englishessays.online/stories.php">Stories</a>
<a target="_blank" href="www.englishessays.online/poems.php">Poems</a>
<a target="_blank" href="www.englishessays.online/about.php">About</a>
<a target="_blank" href="www.englishessays.online/contact.php">Contact</a>
</div>
输出应该是:滚动时固定在顶部的 NAVBAR。 错误是:NAVBAR 固定在初始位置,没有移动到顶部。
【问题讨论】:
标签: javascript php html css