中心对齐 GitHub 自述文件中的shield.io

Zac*_*Zac 4 html markdown github github-flavored-markdown shields.io

我有一个带有 README.md 文件的 GitHub 存储库。我的标题下方有一些盾牌,但它们是左对齐的,而不是居中的。

<a href="">![example1](https://img.shields.io/badge/example-one-red)</a>
<a href="">![example2](https://img.shields.io/badge/example-two-green)</a>
<a href="">![example3](https://img.shields.io/badge/example-three-blue)</a>
Run Code Online (Sandbox Code Playgroud)

然而,我想将它们居中,将它们包装在<div align='center'></div>仅显示原始链接而不是屏蔽图像中。然后,我看到了另一种方法,使用包含在 a 中的 markdown 参考样式链接<h1 align='center'></h1>,如下所示:

[<h1 align="center">
  [![Contributors][contributors-shield]][contributors-url]
  [![Forks][forks-shield]][forks-url]
  [![Stargazers][stars-shield]][stars-url]
</h1>

[contributors-shield]: https://img.shields.io/github/contributors/othneildrew/Best-README-Template.svg
[contributors-url]: https://example.com
[forks-shield]: https://img.shields.io/github/forks/othneildrew/Best-README-Template.svg
[forks-url]: https://example.com
[stars-shield]: https://img.shields.io/github/stars/othneildrew/Best-README-Template.svg
[stars-url]: https://example.com
Run Code Online (Sandbox Code Playgroud)

虽然这按照我的意愿正确地居中对齐了防护罩,但存在一个流氓开放的[情况,如下图所示:

在此输入图像描述

如果我修改上面的代码以将其删除,如下所示:

<h1 align="center">
  [![Contributors][contributors-shield]][contributors-url]
  [![Forks][forks-shield]][forks-url]
  [![Stargazers][stars-shield]][stars-url]
</h1>
Run Code Online (Sandbox Code Playgroud)

我遇到了与以前相同的问题:仅显示原始链接,而不显示屏蔽。这是什么奇怪的行为?我想要实现的目标在 HTML/markdown 中是不可能实现的,还是与屏蔽不兼容?

Chr*_*ris 10

然而,我想将它们居中,将它们包装在<div align='center'></div>仅显示原始链接而不是屏蔽图像中。

在 GitHub 的 GFM 中,您需要使用空行将开始和结束<div>标记与 Markdown 分开

<div align="center">

  <a href="">![example1](https://img.shields.io/badge/example-one-red)</a>
  <a href="">![example2](https://img.shields.io/badge/example-two-green)</a>
  <a href="">![example3](https://img.shields.io/badge/example-three-blue)</a>

</div>
Run Code Online (Sandbox Code Playgroud)

这是因为(强调)

[原始 Markdown] 允许 HTML 块内出现空行。这里禁止它们有两个原因。首先,它消除了解析平衡标签的需要,这种方法成本高昂,并且如果找不到匹配的结束标签,则可能需要从文档末尾回溯。其次,它提供了一种非常简单灵活的方法,将 Markdown 内容包含在 HTML 标签中:只需使用空行将 Markdown 与 HTML 分开

我没有看到任何像[<h1>...您所谓的“替代品”的示例中的内容,但不要以这种方式 滥用<h1>标签

<h1>HTML 规范允许使用多个,但不被认为是最佳实践。仅使用一个<h1>对于屏幕阅读器用户来说是有益的。

语义很重要!只有顶级标题内容才属于<h1>标记,并且每页只能有一个这样的标记。盾牌和徽章绝对不属于那里。