Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用相同的CSS代码为一个id/类实现多个背景图像?_Javascript_Jquery_Html_Css_Web - Fatal编程技术网

Javascript 如何使用相同的CSS代码为一个id/类实现多个背景图像?

Javascript 如何使用相同的CSS代码为一个id/类实现多个背景图像?,javascript,jquery,html,css,web,Javascript,Jquery,Html,Css,Web,所以我的网站有一个横幅id,在我的一个页面上是这样的 #photo-banner { background-attachment: scroll, fixed; background-color: #645862; background-image: url("images/overlay.png"), url("../images/banner3.jpg"); background-position: top left, bottom center; b

所以我的网站有一个横幅id,在我的一个页面上是这样的

#photo-banner {
    background-attachment: scroll, fixed;
    background-color: #645862;
    background-image: url("images/overlay.png"), url("../images/banner3.jpg");
    background-position: top left, bottom center;
    background-repeat: repeat, no-repeat;
    background-size: auto, cover;
    color: white;
    padding: 7em 4.5em 3em 4.5em;
    text-align: center;
}
该id是HTML中某个元素的属性

但是,这只适用于一页。如果我想用相同的其他设置创建另一个具有不同背景图像的页面,据我所知,我需要为此创建另一个id

我认为JS/jQuery有一种方法可以改变HTML文件中的背景图像,而不是CSS文件,从而节省大量的代码编写


或者,如果有其他更好的方法,我也会非常感激,谢谢

第二页的给元素一个类,并使用它覆盖当前的CSS。所有其他CSS都可以保持不变,并将重新使用:

#photo-banner { /* this will apply to page 1 and page 2 */
    background-attachment: scroll, fixed;
    background-color: #645862;
    background-image: url("images/overlay.png"), url("../images/banner3.jpg");
    background-position: top left, bottom center;
    background-repeat: repeat, no-repeat;
    background-size: auto, cover;
    color: white;
    padding: 7em 4.5em 3em 4.5em;
    text-align: center;
}

#photo-banner.page-two { /* this will apply to page two only */
   background-image: url(some-other-image.png), url(some-other-image.png");
}

在第二页,给元素一个类,并使用它覆盖当前的CSS。所有其他CSS都可以保持不变,并将重新使用:

#photo-banner { /* this will apply to page 1 and page 2 */
    background-attachment: scroll, fixed;
    background-color: #645862;
    background-image: url("images/overlay.png"), url("../images/banner3.jpg");
    background-position: top left, bottom center;
    background-repeat: repeat, no-repeat;
    background-size: auto, cover;
    color: white;
    padding: 7em 4.5em 3em 4.5em;
    text-align: center;
}

#photo-banner.page-two { /* this will apply to page two only */
   background-image: url(some-other-image.png), url(some-other-image.png");
}

在第二页,给元素一个类,并使用它覆盖当前的CSS。所有其他CSS都可以保持不变,并将重新使用:

#photo-banner { /* this will apply to page 1 and page 2 */
    background-attachment: scroll, fixed;
    background-color: #645862;
    background-image: url("images/overlay.png"), url("../images/banner3.jpg");
    background-position: top left, bottom center;
    background-repeat: repeat, no-repeat;
    background-size: auto, cover;
    color: white;
    padding: 7em 4.5em 3em 4.5em;
    text-align: center;
}

#photo-banner.page-two { /* this will apply to page two only */
   background-image: url(some-other-image.png), url(some-other-image.png");
}

在第二页,给元素一个类,并使用它覆盖当前的CSS。所有其他CSS都可以保持不变,并将重新使用:

#photo-banner { /* this will apply to page 1 and page 2 */
    background-attachment: scroll, fixed;
    background-color: #645862;
    background-image: url("images/overlay.png"), url("../images/banner3.jpg");
    background-position: top left, bottom center;
    background-repeat: repeat, no-repeat;
    background-size: auto, cover;
    color: white;
    padding: 7em 4.5em 3em 4.5em;
    text-align: center;
}

#photo-banner.page-two { /* this will apply to page two only */
   background-image: url(some-other-image.png), url(some-other-image.png");
}
欢迎来到SO,请阅读。您的问题不太可能得到回答,因为您甚至还没有亲自尝试解决问题,我们也不是来为您做工作的。欢迎来到SO,请阅读。您的问题不太可能得到回答,因为您甚至还没有亲自尝试解决问题,我们也不是来为您做工作的。欢迎来到SO,请阅读。您的问题不太可能得到回答,因为您甚至还没有亲自尝试解决问题,我们也不是来为您做工作的。欢迎来到SO,请阅读。你的问题不太可能得到回答,因为你甚至还没有亲自解决问题,我们也不是来为你做工作的。