多个背景图像

时间:2014-05-22 18:24:29

标签: javascript jquery html css

我想/需要为不同的html页面分配不同的背景图像,意思是

index.html - > background-image:index.jpg
about.html - > background-image:something.jpg
......等等

因此,我想问一下这方面的最佳方法,特定页面的背景是非随机的。有没有办法在CSS或JavaScript甚至某种方式。现在我在html文件中设置每个页面的背景

<body style="background-image:..." >...

感谢您的任何帮助或想法。

1 个答案:

答案 0 :(得分:3)

您可以在htmlbody标记中添加一个类。

HTML:

<html class="page-type-about">
<body>

在CSS中,您可以根据该类指定背景。我还会添加一个默认值。这样,您只需要为那些具有不同于默认背景图像的页面指定不同的图像。

body {
  background-image: url(default-image.png);
}

.page-type-about body {
  background-image: url(about-page-image.png);
}
相关问题