设置自定义锚点

Setting Custom Anchorpoint

本文关键字:自定义 设置      更新时间:2023-09-26

有没有一种方法可以在实际HTML标记之外的位置自定义设置锚点?

我在'使用一个名为'smoothscroll.js'的简单视差滚动脚本http://www.kryogenix.org/code/browser/smoothscroll/smoothscroll.js'

它通过链接到锚点来工作但是,我需要将它们放置在标记所在的位置之外大约200px以上

我尝试过使用类和内联的外部CSS。

EG:

<a name="kids" class="anchor" style="margin-top:-200px;"></a>

<a name="kids" class="anchor" style="margin-top:-200px;"></a>
.anchor { margin-top: -200px; }

有什么建议吗?!

这个问题是这个问题的派生,锚点定位(2-Q点,以获得帮助!)

由于a不是块元素,margin-top将无法按预期工作。

以下是一些经过修改的CSS:

.anchor {
  display: block;
  position: relative; /* relative to the parent container, needed for top/left positioning*/
  top: -200px;
}