Can't give a background color to the image

I'm displaying and image using the background-image property and I also want to make the image a lil bit darker using background-color here's the picture(left one) and here's how I want it to look like (right pic) I also tried background:color url(path) but that didn't work too
No description
No description
19 Replies
Chris Bolson
Chris Bolson2w ago
background-color won't affect the image in any way. It will only work if the image itself has some opacity and the background-color is allowed to show through. Unfortunately it is not possible to set opacity directly on the background image. You could try using blend-mode: background-blend-mode: lighten; but that might work or be enough for your needs. Alteratively you could add the image via a pseudo element, placing it above the background but behind the content and give it (the pseudo element) an opacity.
ἔρως
ἔρως2w ago
or use backdrop-filter it can cause performance issues, but works too or just use a pseudo-element on top of the background image, to make it darker if you use a <figure> instead of a background image, you can even take advantage of lazy loading and async decoding and support more formats and many things by the way, you can have multiple background images too, where the 2nd image is a gradient on top of the image
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
that's a good idea, havent thought of it i will try all the solutions
Chris Bolson
Chris Bolson2w ago
thats a good idea and works well, thanks!
ἔρως
ἔρως2w ago
i can try to think about more ideas, but the 2 backgrounds should be the best
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
it deos not work
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
No description
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
even the blend mode not working @Chris Bolson I will try the pseude element
Chris Bolson
Chris Bolson2w ago
The double background image as suggested by Epic is probably the easiest solution.
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
so I should have two images for this original one and one with dark color right?
Jochem
Jochem2w ago
"red" isn't a blend mode though like, blend modes determine how colors are mixed, you don't put colors in there
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
ooh thought values are colors
Chris Bolson
Chris Bolson2w ago
You don’t need 2 images. Just your image and a linear-gradient with a semi transparent color. https://codepen.io/cbolson/pen/wBBvGXV
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
im already on it after saw ur comment hhh ty buddy thank you chris too
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
it worked
No description
omar_ab(@om4rAb)
omar_ab(@om4rAb)OP2w ago
pretty cool ty @Chris Bolson again
ἔρως
ἔρως2w ago
that is what i meant: the gradient is added as a background image on top of the other image and it gives you a shitton of personalization afterall, it's just a gradient
Chris Bolson
Chris Bolson2w ago
It was Epics suggestion. I just threw a demo together.

Did you find this page helpful?