【问题标题】:Setting Custom Anchorpoint设置自定义锚点
【发布时间】:2012-02-22 03:03:47
【问题描述】:

有没有办法在实际 HTML 标记之外的位置自定义锚点?

我在 'http://www.kryogenix.org/code/browser/smoothscroll/smoothscroll.js' 上使用这个名为“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; }

有什么建议吗?!

这个问题是这个问题的推导,Anchor point positionings(2 - Q 分,求帮助!)

【问题讨论】:

  • 你是否在 CSS 中使用了 position
  • 如'位置:绝对;'?不,我应该吗?
  • 是的,因为它将决定 -200px 所指的内容。

标签: javascript html css


【解决方案1】:

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

这是一些修改后的 CSS:

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

【讨论】:

  • 我使用了 position: absolute;并通过内联样式设置边距。不过谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-04-22
  • 2020-11-14
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
  • 2018-02-27
  • 1970-01-01
  • 2020-12-31
相关资源
最近更新 更多