不同页面的 Sphinx 不同背景图片

Sphinx different background images for different pages

我在 Sphinx 网站上工作,我将 index.html 作为基本布局。它有一个我在 css 文件中定义的背景图像。我有导航栏链接,如关于、项目等。我想在这些链接上使用背景颜色而不是背景图像,我该如何实现?我在 RST 文件上试过这个:

.. raw:: html

<embed>
   <style>
      body {
      background-color:white !important;
      }
   </style>
</embed>

但是这段代码不起作用。有什么办法可以实现吗?

假设您看到的是您在别处设置的背景图片而不是背景颜色 ("it does not work"),您还必须覆盖 background-image: url('foo.png'); CSS 属性 .

.. raw:: html

<embed>
   <style>
      body {
        background-color: white;
        background-image: none !important;
      }
   </style>
</embed>

不过,我认为这是一种丑陋的处理方式。

我更愿意使用 Jinja2 模板和外部样式 sheet。换句话说,修改您的 Jinja2 模板以将 id="{{ pagename }}" 插入到 <body> 标记中。 id 的值在所有页面中必须是唯一的。然后在我的自定义样式 sheet 中,添加合适的选择器:

body#index {
    background-color: white;
}

body#subpage {
    background-image: url('moosehair.png');
}