You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在GitHub Markdown中创建类似官方示例的导航标签页?

Can you create navigation tabs like the GitHub Guides example in GitHub-flavored Markdown?

Unfortunately, you can't create fully interactive, style-matched navigation tabs using pure GitHub-flavored Markdown (GFM). The tabs you see in GitHub's official guides are powered by custom JavaScript and CSS that's part of their website's theme—this isn't part of the standard Markdown spec or GFM extensions.

That said, there are a couple of workarounds to mimic tab-like behavior or appearance, even if they don't replicate the exact interactive experience:

1. Static Tabbed Appearance (Non-Interactive)

You can use HTML and inline CSS to create a visual tab layout, though clicking won't switch content. This works because GitHub allows limited HTML and inline styling:

<div style="display: flex; border-bottom: 1px solid #e1e4e8;">
  <div style="padding: 8px 16px; background: #f6f8fa; border: 1px solid #e1e4e8; border-bottom: none; border-radius: 4px 4px 0 0; font-weight: bold;">Tab 1</div>
  <div style="padding: 8px 16px; border: 1px solid transparent; border-bottom: 1px solid #e1e4e8; border-radius: 4px 4px 0 0;">Tab 2</div>
  <div style="padding: 8px 16px; border: 1px solid transparent; border-bottom: 1px solid #e1e4e8; border-radius: 4px 4px 0 0;">Tab 3</div>
</div>
<div style="padding: 16px; border: 1px solid #e1e4e8; border-top: none; border-radius: 0 0 4px 4px;">
  Content for Tab 1 (static—you'd need to duplicate this block for other tabs if you want separate content visible at once)
</div>

This will render a static tab bar with a content area, but it won't switch content when clicking tabs.

2. Makeshift Interactive "Tabs" with Details/Summary

If you need collapsible content that acts like tabs (but looks different), you can use GFM's built-in <details> and <summary> elements. While not a perfect match, it's a native way to hide/show content without custom code:

Tab 1

Click to view Tab 1 content This is the content for Tab 1. You can include standard Markdown here: lists, code blocks, links, etc. ```python print("Hello from Tab 1") ```

Tab 2

Click to view Tab 2 content Content for Tab 2 goes here. This approach is fully supported in GFM and works across all GitHub platforms.

Important Notes

  • GitHub sanitizes HTML input, so many advanced CSS properties or JavaScript will be stripped out—you can't replicate the full interactive tab functionality seen in the official guides.
  • Any workarounds will be limited in appearance and interactivity compared to custom site tabs.

内容的提问来源于stack exchange,提问作者Ivan Perez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 06:56:35