【问题标题】:Adding CSS class to anchor link in markdown (Hugo)将 CSS 类添加到 Markdown 中的锚链接(Hugo)
【发布时间】:2021-04-03 12:44:14
【问题描述】:

我在我的.markdown 文档中使用锚链接,如下所示:

# {#infrared}

这很好,但我想实现以下 CSS,以便链接滚动到页面中间而不是顶部:

.anchor {
  position: absolute;
  transform: translateY(-50vh);
}

如何将 anchor 类添加到 Markdown 文档中的锚链接?

【问题讨论】:

    标签: html css markdown hugo


    【解决方案1】:

    基于这个答案here,我们有:

    根据 Goldmark 的 README 1,Markdown 处理器是 目前在 Hugo 中默认开启:

    目前只有标题支持属性…

    ## heading ## {#id .className attrName=attrValue class="class1 class2"}
     
    ## heading {#id .className attrName=attrValue class="class1 class2"}
    

    【讨论】:

      【解决方案2】:

      我认为整体 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

      【讨论】:

      • Markdown 实际上应该支持这一点,但我正在使用 RStudio 构建它,并且由于某种原因,HTML 不会在页面上呈现。谢谢你的回答,我也会浏览链接:)
      • 我认为它支持 Fenced 代码属性,但我对此不是 100% 确定
      猜你喜欢
      • 2011-09-03
      • 2016-01-18
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多