【发布时间】:2021-04-03 12:44:14
【问题描述】:
我在我的.markdown 文档中使用锚链接,如下所示:
# {#infrared}
这很好,但我想实现以下 CSS,以便链接滚动到页面中间而不是顶部:
.anchor {
position: absolute;
transform: translateY(-50vh);
}
如何将 anchor 类添加到 Markdown 文档中的锚链接?
【问题讨论】:
我在我的.markdown 文档中使用锚链接,如下所示:
# {#infrared}
这很好,但我想实现以下 CSS,以便链接滚动到页面中间而不是顶部:
.anchor {
position: absolute;
transform: translateY(-50vh);
}
如何将 anchor 类添加到 Markdown 文档中的锚链接?
【问题讨论】:
基于这个答案here,我们有:
根据 Goldmark 的 README 1,Markdown 处理器是 目前在 Hugo 中默认开启:
目前只有标题支持属性…
## heading ## {#id .className attrName=attrValue class="class1 class2"}
## heading {#id .className attrName=attrValue class="class1 class2"}
【讨论】:
我认为整体 Markdown 支持 html 标签,例如你应该可以使用
<p class="anchor">text...</p>
但无论哪种方式,如果它不会真正起作用,您几乎没有其他选择。 例如“Fenced Code Attributes”:
```{.red .numberLines startFrom="1"}
Here is a paragraph.
And another.
```
这确实是从文档中复制的示例, 这里确实有更多选择: https://lifelongprogrammer.blogspot.com/2019/01/how-to-style-markdown-with-css.html
【讨论】: