【问题标题】:Sphinx different background images for different pagesSphinx 不同页面的不同背景图像
【发布时间】:2017-11-12 01:55:18
【问题描述】:

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

.. raw:: html

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

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

【问题讨论】:

  • “它不起作用”是什么意思?你观察到什么?

标签: python html css python-sphinx restructuredtext


【解决方案1】:

假设您看到的是在别处设置的背景图像而不是背景颜色(“它不起作用”),您还必须覆盖 background-image: url('foo.png'); CSS 属性。

.. raw:: html

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

不过,我认为这是一种丑陋的做法。

我更喜欢使用 Jinja2 模板和外部样式表。换句话说,修改您的 Jinja2 模板,将 id="{{ pagename }}" 插入到 &lt;body&gt; 标记中。 id 的值在您的所有页面中必须是唯一的。然后在我的自定义样式表中,添加适当的选择器:

body#index {
    background-color: white;
}

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

【讨论】:

    猜你喜欢
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多