狮身人面像不同页面的不同背景图像

时间:2017-06-09 23:52:30

标签: python html css python-sphinx restructuredtext

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

.. raw:: html

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

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

1 个答案:

答案 0 :(得分:2)

假设您看到在其他地方设置的背景图像而不是背景颜色(&#34;它不起作用&#34;),您也必须覆盖background-image: url('foo.png'); CSS属性。

.. raw:: html

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

我认为这是一种丑陋的方式。

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

body#index {
    background-color: white;
}

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