【问题标题】:How to create an offset over an anchor link?如何在锚链接上创建偏移量?
【发布时间】:2020-03-02 23:24:07
【问题描述】:

在我的网站上,我有带有固定导航栏的 Bootstrap 3 主题。

导航栏隐藏了一些文本。

如何在锚链接上创建偏移量?

【问题讨论】:

标签: html css hyperlink anchor href


【解决方案1】:

在样式:target { padding-top: 10%;}中添加以下伪元素,将10%的值替换为导航栏的高度。

:target {
  border: 2px solid #D4D4D4;
  background-color: #e5eecc;
  padding-top:10%;
}
<!DOCTYPE html>
<html>
<head>
<title>Sample code</title>
</head>
<body>

<h1>This is a heading</h1>

<p><a href="#news1">Jump to New content 1</a></p>
<p><a href="#news2">Jump to New content 2</a></p>

<p>Click on the links above and the :target selector highlight the current active HTML anchor.</p>

<p id="news1"><b>New content 1...</b></p>
<p id="news2"><b>New content 2...</b></p>

<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :target selector.</p>

</body>
</html>

【讨论】:

  • 谢谢,我会测试所有这些解决方案
  • 最后你的答案不完整。文本正确显示在固定导航栏下方。但是我回去,有一个白色的填充。
  • 我找到了解决方案,效果很好html { scroll-padding-top: 81px; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-12
  • 2015-12-12
  • 2018-03-16
相关资源
最近更新 更多