【问题标题】:Change background image opacity, without affecting max-height, max-width改变背景图片不透明度,不影响 max-height, max-width
【发布时间】:2016-04-12 15:40:14
【问题描述】:

我遇到了一个问题,我有一个背景图像我想将不透明度设置为 0.35,我看到通过使用图像作为标签,使用绝对属性可以欺骗 CSS 没有背景图像不透明度选择器。我还在其他图像上设置了最大宽度,所以当我尝试这样做时,我的所有图像都恢复到原来的巨大尺寸。这是我的代码,任何答案都会有所帮助,我恢复到具有最大宽度图像的原始代码。

     html {
    background-image: url(*image url*);
    background-repeat: no-repeat;
    background-size: cover;

}
img {
    max-width: 100px;
    max-height: 100px;
}
.navBar {
    color: white;
    text-align: right;
}

【问题讨论】:

  • 背景图片不在 html 标签上。将其更改为 body 标签。另外,不知道为什么要更改背后没有任何东西的图像的不透明度?
  • 当然背景图片可以放在 html 标签上 - 将它移到 body 上没有区别。
  • 这是一张深色图片,我要选择深色主题

标签: html css image background-image opacity


【解决方案1】:

试试这个

 html {
        background-image: url(*image url*);
        background-repeat: no-repeat;
        background-size: cover;

    }
    body {
        background: rgba(255, 255, 255, 0.53);
    }

【讨论】:

  • 仅代码的答案很可能对未来的访问者甚至 OP 本人都没有帮助。考虑编辑您的答案以包含代码解释。
猜你喜欢
  • 2013-07-03
  • 2021-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-12
  • 2011-07-06
  • 1970-01-01
  • 2019-08-02
相关资源
最近更新 更多