How to add custom css file to Sphinx?

前端 未结 4 507
故里飘歌
故里飘歌 2020-12-02 15:25

How I can add custom css file? The following config does not work for me:

# conf.py
html_static_path = [\'_static\']
html_theme = \'default\'
html_theme_opti         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 16:14

    You should be able to include custom css by extending the default sphinx theme. In your conf.py you would specify where your extension to the theme would be, such as.

    # Add any paths that contain templates here, relative to this directory.
    templates_path = ['_templates']
    

    Then in _templates you would create a extension to the default theme named 'layout.html' that would include your cssfiles such as.

    {# layout.html #}
    {# Import the layout of the theme. #}
    {% extends "!layout.html" %}
    
    {% set css_files = css_files + ['_static/style.css'] %}
    

    See sphinx's documentation on templating for more information.

提交回复
热议问题