【发布时间】:2013-02-14 21:16:32
【问题描述】:
我的页面有一个固定的顶部导航栏,页面上有几个 id 元素。如果我按下这些 id 元素之一的链接,它会将这个 id 滚动到顶部,但它隐藏在顶部导航栏下。在野外,页面很长,并且有不同的“跳转点”。
我有a simplified fiddle to show the problem 带有以下html
<div id="fixedbar">This is the fixed top bar</div>
<div id="toplinks"><a href="#first">First</a> <a href="#second">Second</a></div>
<p id="first"><strong>First</strong>
Lorem ipsum dolor sit amet[...]
</p>
<p id="second"><strong>Second</strong>
Duis autem vel eum iriure dolor[...]
</p>
<div id="bottomlinks"><a href="#first">First</a> <a href="#second">Second</a></div>
还有这个css
body{padding:0;margin:0}
#toplinks{padding-top:2em}
#fixedbar{
position:fixed;
background-color:#ccc;
height:2em;
width:100%
}
我希望点击链接滚动到正确的元素,但补充固定的导航栏。 一个可能的解决方案最好只包含 css,但可以包含 javascript 或 jquery(1.9 用于生产)。
感谢您的帮助!
【问题讨论】:
标签: javascript jquery html css