【问题标题】:How to change the rtd background color?如何更改 rtd 背景颜色?
【发布时间】:2018-01-31 10:34:31
【问题描述】:
我想为 sphinx-doc 更改 Read the Docs theme 的背景颜色。
主题是使用 sass 编写的,我发现变量 $section-background-color 被定义为 no-where。
如果我在项目中的任何位置将#2980B9 替换为另一个值,它就不起作用。这种疯狂的蓝色仍然是从某个地方检索到的。
这个背景色是在哪里定义的?
我还尝试将_theme_variables_sass 中的所有$blue 替换为$red。
【问题讨论】:
标签:
css
sass
python-sphinx
read-the-docs
【解决方案1】:
有(至少)两种方法可以改变 sphinx_rtd_theme 样式:
- 编辑用于构建主题的源 SASS,如docs 中所述。请确保 Sphinx 使用的是您新建的 sphinx_rtd_theme,而不是 PyPI 安装的(原始)版本。
- 使用自定义 CSS 文件覆盖所需的 CSS 规则,如回答 here。
我发现#2 要简单得多。例如,假设我想更改侧面标题、徽标和搜索栏后面的背景颜色。查看默认构建(检查页面样式),背景颜色设置在 .wy-side-nav-search 类中,因此只需在 <project-dir>/_static/css 中创建一个带有类的 custom.css 文件
.wy-side-nav-search{ background-color:<#yourHexColor> }
然后,在 conf.py 中添加:
def setup (app):
app.add_stylesheet('css/custom.css')
make clean、make build 和中提琴。
至于定义背景颜色的位置,我还没有看够远,无法说出,但希望这能让您(和未来的访问者)获得想要的结果。
【解决方案2】:
与 NickT 的回答一样,但使用 css 变量,并设置移动版本标题颜色 -
body {
--themecolor: black;
}
.wy-side-nav-search {
background-color: var(--themecolor);
}
.wy-nav-top {
background-color: var(--themecolor);
}