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

如何在R Markdown的_site.yml中拆分导航栏文本为两行

解决R Markdown网站导航栏文本换行问题

要实现导航栏文本换行,需要结合HTML标签和自定义CSS(默认导航栏样式会强制文本不换行),具体步骤如下:

  1. 修改_site.yml中的导航项文本,使用HTML的<br>标签插入换行:
name: "SampleWeb"
navbar:
  title: "SampleWeb"
  left:
    - text: "Home"
      href: index.html
    - text: "Descriptive Analysis"
      href: descriptive_analysis.html
    - text: "Baseline GWAS<br>Covariate-Sex"
      href: gwas_baseline.html
  1. 在网站根目录创建styles.css文件,覆盖导航栏的强制不换行样式:
.navbar-nav li a {
  white-space: normal;
  line-height: 1.2; /* 可根据需求调整行高,优化两行文本的间距 */
}
  1. 在_site.yml中引入这个CSS文件,确保样式生效:
name: "SampleWeb"
navbar:
  title: "SampleWeb"
  left:
    - text: "Home"
      href: index.html
    - text: "Descriptive Analysis"
      href: descriptive_analysis.html
    - text: "Baseline GWAS<br>Covariate-Sex"
      href: gwas_baseline.html
output:
  html_document:
    css: styles.css

完成以上步骤后重新构建网站,导航栏中的"Baseline GWAS Covariate-Sex"就会拆分为两行显示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 19:29:59