【发布时间】:2019-07-03 21:43:45
【问题描述】:
给定一个固定的导航和一些带有锚点的部分;单击哈希链接时 - 固定导航与部分锚点重叠。
我看过一些类似的帖子,但似乎找不到适合我的特定情况的解决方案。
由于项目限制,我无法覆盖 .anchor 样式或使用 JavaScript 修复该偏移或 add any additional HTML elements。
虽然我可以在.anchor - the hack with a height and a negative margin 中添加一个伪元素来平衡它,但在我的情况下不起作用,因为.anchor 具有顶部填充和边框。
<h3 class="anchor" id="section-1">Title 1</h3>
<p>Description 1</p>
<h3 class="anchor" id="section-2">Title 2</h3>
<p>Description 2</p>
<h3 class="anchor" id="section-3">Title 3</h3>
<p>Description 3</p>
.nav {
position: sticky;
}
.anchor {
border-top: 1px solid #333940;
margin-top: 2rem;
padding-top: 2rem;
}
.anchor::before {
}
谁能帮我弄清楚是否有纯 CSS 方式来修复锚点的偏移量?
【问题讨论】: