How to change the rtd background color?

流过昼夜 提交于 2019-12-11 16:10:36

问题


I would like to change the background color of the Read the Docs theme for sphinx-doc.

The theme is written using sass and I find the variable $section-background-color which is defined no-where.

If I replace the #2980B9 with another value anywhere in the project, it doesn't work. This insane blue is still retrieved from somewhere.

Where is this background color defined?

I also tried to replace all the $blue with $red in _theme_variables_sass.


回答1:


There are (at least) two ways to change sphinx_rtd_theme styling:

  1. Edit the source SASS used to build the theme as outlined in the docs. Just be sure Sphinx is using your newly built sphinx_rtd_theme, rather than the PyPI-installed (original) version.
  2. Override the desired CSS rules with a custom CSS file as answered here.

I find #2 to be much simpler. As an example, say I wanted to change the background color behind the title, logo and search bar in the side. Looking at the default build (inspecting the page styles), the background color is set in the class .wy-side-nav-search, so just create a custom.css file inside <project-dir>/_static/css with class

.wy-side-nav-search{ background-color:<#yourHexColor> }

Then, in conf.py add:

def setup (app): app.add_stylesheet('css/custom.css')

make clean, make build and viola.

As for where the background color is defined, I haven't looked far enough to be able to say, but hopefully this gets you (and future visitors) the desired outcome.



来源:https://stackoverflow.com/questions/48540008/how-to-change-the-rtd-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!