大家好

在替换图像方面,我需要您的帮助。

实际上,我正在使用CSS和HTML编写博客。我想在某些帖子中将背景图片替换为其他图片。

原始css有:

body{
    background:#000000 url(image.jpg) no-repeat top center;
    color:#fff;
    font:x-small Georgia Serif;
    font-size:small;
    text-align:left;
    margin:0;
    background-attachment:fixed;
}


因此,在某些帖子中,我使用此CSS“技巧”将另一张图片替换为原始背景图片(在帖子内部)

body{
    background:#000000 url(image2.jpg) no-repeat top center;
    color:#fff;
    font:x-small Georgia Serif;
    font-size:small;
    text-align:left;
    margin:0;
    background-attachment:fixed;
}


我可以添加类似的东西吗

如果div class =“ post1”
不要下载图像1。仅下载image2。

这样一来,在浏览器中,浏览器无需下载两个图像,也无需花费更多时间。

如果问题不大,请先谢谢,并表示抱歉。

最佳答案

给主体一个类,并在该类中定义背景。

第一页:

<body class="background1">*Content*</body>


第二页:

<body class="background2">*Content*</body>


CSS:

body{
  color:#fff;
  font:small Georgia Serif;
  text-align:left;
  margin:0;
  background-attachment:fixed;
}

.background1 { background:#000000 url(image1.jpg) no-repeat top center; }
.background2 { background:#000000 url(image2.jpg) no-repeat top center; }

10-05 20:40
查看更多