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

如何为Distill R Markdown网站添加可点击的导航子菜单?

解决Distill网站导航栏二级子菜单不可点击的问题

问题原因

Distill框架的导航栏原生仅支持一级下拉菜单,你配置的二级子菜单显示灰色不可点击,是因为框架没有为多级菜单编写对应的交互逻辑和样式支持。而普通R Markdown HTML文档依赖Bootstrap原生导航组件,天然支持多级子菜单,所以能正常使用。

解决方案

方案1:调整为一级菜单结构(推荐,无兼容性问题)

直接将二级子项合并到一级下拉菜单中,修改_site.yml如下:

name: "submenuTest"
title: "Submenu test"
description: |
  Submenu test
output_dir: "_site"
navbar:
  right:
    - text: "Home"
      href: index.html
    - text: 'Menu'
      menu:
      - text: 'Page'
        href: page.html
      - text: 'Sub Page'
        href: subpage.html
output: distill::distill_article

方案2:自定义CSS实现二级子菜单(hack方式,需维护)

如果必须保留二级层级结构,可以通过自定义样式强制开启交互:

  1. 在网站根目录创建styles.css文件,添加以下样式:
/* 触发hover时显示二级子菜单 */
.navbar-nav .dropdown-menu .dropdown-item.has-submenu:hover .dropdown-submenu {
  display: block;
  position: absolute;
  left: 100%;
  top: 0;
  border: 1px solid #eee;
  border-radius: 0.25rem;
  margin-left: 0.1rem;
}

/* 修复二级子项的灰色不可点击样式 */
.navbar-nav .dropdown-submenu .dropdown-item {
  color: #212529;
  cursor: pointer;
  padding: 0.5rem 1.5rem;
}

.navbar-nav .dropdown-submenu .dropdown-item:hover {
  background-color: #f8f9fa;
}
  1. 在_site.yml中引入这个样式文件:
name: "submenuTest"
title: "Submenu test"
description: |
  Submenu test
output_dir: "_site"
navbar:
  right:
    - text: "Home"
      href: index.html
    - text: 'Menu'
      menu:
      - text: 'Page'
        href: page.html
      - text: 'Submenu'
        menu:
        - text: 'Sub Page'
          href: subpage.html
output: distill::distill_article
includes:
  in_header: styles.css

注意:这种自定义方式可能会随着Distill版本更新出现兼容性问题,需要后续跟进调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 22:01:01