更改Sphinx阅读文档主题的颜色?

fal*_*cat 14 colors read-the-docs

我正在为我的API库构建文档,而我正在使用readthedocs.io来托管文档,并使用Sphinx支持.我为Sphinx使用安装了Read The Docs主题pip install,而Read the Docs网站目前正在运行文档.

我想改变文档的颜色.我已经通过他们的GitHub存储库GitHub.com进行了一些搜索,并看到了一些关于编辑sass文件的讨论.但是,我似乎无法找到这些文件的位置.

使用其他颜色读取文档的示例

任何帮助表示赞赏!

Aid*_*ick 16

我相信规范的方法是创建一个_static文件夹,在其中包含CSS文件,然后使用文件夹中的include引用模板中的CSS _templates.

为了演示这一点,您可以尝试简单地覆盖该layout.html文件:首先,_templates在docs文件夹中创建(如果它尚不存在),然后创建一个名为的文件layout.html.

使用以下内容填充:

{% extends "!layout.html" %}
  {% block footer %} {{ super() }}

  <style>
    /* Sidebar header (and topbar for mobile) */
    .wy-side-nav-search, .wy-nav-top {
      background: #00ff00;
    }
    /* Sidebar */
    .wy-nav-side {
      background: #ff0000;
    }
  </style>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

一旦你重建了你的文档,你应该看到一个花哨的侧栏和标题.(我在Sphinx/Read The Docs主题实现中使用了类似的技术.查看源代码等以查看我们覆盖的位数.)

  • 如果您只想更改主题的最简单颜色,那么这个答案非常有效。谢谢。 (2认同)
  • 如果不清楚(即,如果您像我一样是菜鸟),您可以将 `&lt;style&gt;` 块替换为 `&lt;link rel="stylesheet" type="text/css" href="_static/custom。 css"&gt;` 并将 CSS 代码放入 `_static/custom.css` 中,只要您的 `conf.py` 包含 `html_static_path = ['_static']`。 (2认同)

Gus*_*rra 9

您可以通过将自定义 CSS 文件添加到_static. 要真正让 Sphinx 使用该文件,请将其添加到您的conf.py

def setup(app):
    app.add_css_file('custom.css')
Run Code Online (Sandbox Code Playgroud)

示例 CSS ( custom.css) 将侧边栏颜色更改为深绿色(基于@afit 的回答):

.wy-side-nav-search, .wy-nav-top {
    background: #0b750a;
}

Run Code Online (Sandbox Code Playgroud)


Azm*_*sov 7

html_css_files添加 CSS 文件的一种更简单的方法是在 conf.py 中设置:

# custom.css is inside one of the html_static_path folders (e.g. _static)
html_css_files = ["custom.css"]
Run Code Online (Sandbox Code Playgroud)

请参阅:https ://docs.readthedocs.io/en/latest/guides/adding-custom-css.html


小智 5

如果你只是想改变导航标题的颜色,你可以使用这样做html_theme_options的变量conf.py。有一个参数叫做'style_nav_header_background'.

https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html#theme-options