如何用css让background背景图片变暗一些?
网友回复
我们可以使用 background-blend-mode 属性来使 CSS 中的背景图像变暗。该属性设置背景的混合模式。此属性有多种选择。一些选项是 normal、multiply、darken、lighten, saturation 等。我们可以使用变暗选项使背景图像更暗。我们可以使用 rgba() 函数设置背景图像的颜色。 例如,在 CSS 中选择 background id 并使用 background 属性设置颜色和背景图像。将颜色设置为 rgba(0, 0, 0, 0.7) 并在 url() 函数中使用占位符图像。使用与第一种方法不同的背景属性来正确设置图像。接下来,使用 background-blend-mode 属性并将其设置为 darken。 通过这种方式,我们可以使用 background-blend-mode 属性使背景图像变暗。 示例代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <title>BFW NEW PAGE</title> <style> #oldbackground{ background: url('//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png'); height: 200px; width: 300px; background-position: center; background-repeat: no-repeat; background-size: cover; } #background{ background: rgba(0, 0, 0, 0.6) url('//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png'); height: 200px; width: 300px; background-position: center; background-repeat: no-repeat; background-size: cover; background-blend-mode: darken; } </style> </head> <body> <div id="oldbackground"></div> <div id="background"></div> </body> </html>
如何是img标签,可以使用filter: brightness(0.75);实现,具体代码如下:
<img style="filter: brightness(0.75);" src="//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png" /> <!--图片变暗--> <img style="filter: brightness(50%);" src="//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png" /> <!--图片变暗--> <img style="filter: brightness(30%);" src="//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png" />