Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何使文章多级目录自动展开,而不是默认折叠 #710

Closed
blueyi opened this issue Mar 9, 2016 · 6 comments
Closed

如何使文章多级目录自动展开,而不是默认折叠 #710

blueyi opened this issue Mar 9, 2016 · 6 comments

Comments

@blueyi
Copy link

blueyi commented Mar 9, 2016

如下图所示,默认情况下文章的多级目录是折叠的,需要点击一下才能打开,希望可以打开文章时自动展开。谢谢
13

@iissnan
Copy link
Owner

iissnan commented Mar 9, 2016

默认展开需要改动 CSS 和 JavaScript,滚动时可能会自动收缩。

另外,默认展开一个潜在的问题是:在目录很多的情况下,内容会超出并不可见。这是一个已知的 Bug。

@blueyi
Copy link
Author

blueyi commented Mar 9, 2016

@iissnan 谢谢,我的文章中目录有点类似分节的标签,为了方便定位,因为多数笔记都很长,但目录不会太长,如果目录不展开的话,很不方便查看。如果改动CSS和JS的工作太多,是否有其他替代方式呢,谢谢

@ruiqiangJiao
Copy link

可以在文章二级标题部分加上锚点,可以在手机端方便查看

@blueyi
Copy link
Author

blueyi commented Mar 10, 2016

@ruiqiangJiao 谢谢

@Coodool
Copy link

Coodool commented Oct 25, 2018

如果你想实现默认展开全部目录的功能,可以在themes/next/source/css/_custom/custom.styl文件中添加以下自定义样式规则:

.post-toc .nav .nav-child { 
    display: block; 
}

但是通常文章内会出现多级标题,对应的目录里就会有多级导航出现,这时候一些原本你不希望出现的次要标题也会在目录中出现并且无法折叠。可以通过以下样式实现默认只展开两级目录,这样以来就完美解决了该问题。

.post-toc .nav .nav-level-1>.nav-child { 
   display: block; 
}

本人博客 Yearito's Blog将于近期上线,希望能为你的建站之路提供更多的帮助。

@s1mplecc
Copy link

@Coodool 正解!感谢大神

我是调整了展开至 Markdown 三级标题。

.post-toc .nav .nav-level-2>.nav-child { 
   display: block; 
}

添加完成后记得使用 hexo clean; hexo g -d 重新渲染。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants