【发布时间】:2012-03-09 10:19:36
【问题描述】:
我有一个固定的标题高度 50 像素。在我的身体里,我有很多锚。问题是,当我点击指向锚点的链接时,锚点出现在我的固定标题下,我丢失了 50 像素的内容(我需要向上滚动 50 像素才能阅读标题下的内容)。
有没有办法将锚定边缘设置为 50 像素?我的身体充满了很多盒子(div),它们之间有一个边距,所以我不能放置一个 50px 的空 div,然后在它后面锚定..
html:
<div id="header"></div>
<div id="content">
<div class="box" id="n1"></div>
<div class="box" id="n2"></div>
<div class="box" id="n3"></div>
</div>
css:
#header{
height: 40px;
width: 100%;
margin: 0px;
padding: 0px;
position: fixed;
text-align: center;
z-index:2;
}
#content{
padding-top: 50px;
margin: 0px;
}
.box {
width: 80%;
margin-left: auto;
margin-right: auto;
vertical-align : top;
padding: 1.4%; /* Keep it in percent (%) */
margin-bottom: 30px;
min-height: 200px;
}
【问题讨论】:
-
这可以帮助固定标题的锚链接:pixelflips.com/blog/anchor-links-with-a-fixed-header