修改 Sphinx 主题“阅读文档”的内容宽度

新手上路,请多包涵

我正在为我的文档使用“阅读文档”Sphinx 主题。在原始主题中,如下所示

http://read-the-docs.readthedocs.org/en/latest/theme.html

内容或主要布局宽度设计为适合移动设备。但是,对于我的项目,我希望它更宽一些。我不知道 HTML,因此如果有人能给我一些增加内容(布局)宽度的线索,我将不胜感激。

原文由 hypersonics 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

另一种选择是在 source/_static 中创建一个样式表,只使用你想要的 css,例如

.wy-nav-content {
    max-width: none;
}

要么

.wy-nav-content {
    max-width: 1200px !important;
}

确保在 source/conf.py 中引用了该目录——我相信默认情况下有一条线可以做到这一点,即

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

然后在 source/_templates/layout.html 中创建一个自定义布局 --- 并执行类似这样的操作以包含您的样式表

{% extends "!layout.html" %}
{% block extrahead %}
    <link href="{{ pathto("_static/style.css", True) }}" rel="stylesheet" type="text/css">
{% endblock %}

假设您调用了样式表 style.css

原文由 Leo 发布,翻译遵循 CC BY-SA 3.0 许可协议

如果有人正在寻找更简单的答案……结合 https://samnicholls.net/2016/06/15/how-to-sphinx-readthedocs/ 的想法和上述建议,我找到了最简单的方法自定义窗口宽度如下:

  1. conf.py 中,添加一个添加自定义样式表的函数:
    def setup(app):
       app.add_css_file('my_theme.css')

  1. conf.py 中,状态/调整:
    html_static_path = ['_static']

  1. 创建一个 _static 文件夹/目录(如果不存在)。

  2. _static 文件夹中创建一个名为 my_theme.css 的文件,其中包含以下行:

    .wy-nav-content {
       max-width: 1200px !important;
   }

原文由 se_pp 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题