【发布时间】:2014-10-14 23:30:33
【问题描述】:
当我单击固定导航栏上的链接时,它会跳转到页面上的特定部分,但固定导航栏的高度会溢出。我怎样才能减去那个高度?这需要 javascript/jquery 吗?
<div id="fixedNavWrapper">
<div id="navLinks">
<ul>
<li><a href="#about">ABOUT ME</a></li>
<li><a href="#portfolio">PORTFOLIO</a></li>
</ul>
</div>
</div>
<section id="about" class="section">
<h2>ABOUT ME</h2>
</section>
.CSS:
#fixedNavWrapper {
position: fixed;
z-index: 1;
width: 100%;
top: 0;
left: 0;
}
#navLinks {
text-align: center;
width: 100%;
height: 57px;
background: #000000;
}
#navLinks ul {
list-style: none;
margin: 0;
padding: 5px;
display: inline-block;
}
#navLinks ul li {
margin: 0;
padding: 0;
display: inline;
}
#navLinks ul li a {
text-decoration: none;
display: block;
float: left;
padding: 0 65px;
height: 45px;
line-height: 45px;
}
【问题讨论】:
-
这被称为“固定导航栏覆盖锚链接”,有多种解决方案。我用这个:stackoverflow.com/a/20320919/1004312
标签: html css hyperlink navbar fixed