更多Markdown使用技巧,可参考《Markdown使用方法、常用技巧汇总》
Markdown中,锚的使用对阅读体验有很大的提升,但不同工具、平台对锚的支持不尽相同,踩了不少坑,整理做个记录和分享。
使用锚点的方式普遍相同:
- 页外链接:
[描述](url)
页外链接比较简单,拿到url按上面写法即可使用。如点我去首页 - 页内锚点:
[描述](#id)
页内锚点的引用方式如上,但定义的方式有些不同。这是在markdown编写时常遇到的问题。下面主要介绍该项。
如何定义页内锚点
尽管Markdown是HTML的子集,但不同Markdown工具对语法的解释和支持有一些出入:
- 标准markdown语法支持
<a name=xxx></a>
- csdn、简书等不支持,需要使用
<a id=xxx></a>
或<h5 id=xxx>xxx</h5>
的方式;注意该链接会直接跳到页面顶部,如果考虑体验,可以将锚放置在目标元素上面一行。