跳至主要内容

使用折叠节组织信息

您可以通过使用 <details> 标签创建折叠章节来简化 Markdown。

谁可以使用此功能?

Markdown 可在 GitHub 网页界面中使用。

本文内容

创建折叠章节

您可以通过创建折叠章节来临时隐藏 Markdown 的部分内容,读者可以自行展开。例如,当您想在议题评论中加入技术细节,而这些细节并非所有读者都相关或感兴趣时,您可以将这些细节放入折叠章节。

<details> 块中的任何 Markdown 都会被折叠,直至读者点击以展开详细信息。

<details> 块中,使用 <summary> 标签来向读者说明内部内容。该标签显示在.

<details>

<summary>Tips for collapsed sections</summary>

### You can add a header

You can add text within a collapsed section.

You can add an image or a code block, too.

```ruby
   puts "Hello World"
```

</details>

默认情况下,<summary> 标签内部的 Markdown 将被折叠。

Screenshot of the Markdown above on this page as rendered on GitHub, showing a right-facing arrow and the header "Tips for collapsed sections."

当读者点击后,详细信息将展开

Screenshot of the Markdown above on this page as rendered on GitHub. The collapsed section contains headers, text, images, and code blocks.

可选地,若希望章节默认展开,可在 <details> 标签上添加 open 属性。

<details open>

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.