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

Nextra浮动TOC无法显示在右侧侧边栏问题求助

解决Nextra主题TOC右侧浮动的配置方法

要将TOC(目录)移到右侧侧边栏浮动显示,你需要修改theme.config.js中的toc配置项,将原本的布尔值true替换为包含float属性的配置对象:

  • 核心配置是给toc对象添加float: 'right'属性
  • 可按需添加depth属性控制TOC显示的标题层级(比如只展示h2和h3)

修改后的完整配置代码:

import { useTheme } from 'next-themes'

export default {
  logo: () => {
    const { theme } = useTheme()

    return (
      <img 
        src={theme === 'dark' ? '/images/logo/logo-white.svg' : '/images/logo/logo-grey.svg'} 
        alt="Logo" 
        style={{ height: '40px' }} /* Adjust as needed */
      />
    )
  },
  toc: {
    float: 'right',
    // 可选配置:控制TOC显示的标题层级范围,示例为仅展示h2、h3
    depth: [2, 3]
  },
  // 其他配置选项
}

额外说明:
如果需要自定义右侧TOC的样式(比如宽度、间距),可以在全局样式文件中添加自定义CSS:

.toc.float-right {
  width: 280px;
  margin-left: 2rem;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 14:19:51