Having problems where I have a background gradient and a background image (transparent PNG) for my div, but no matter what, only the color gradient will display and not the image. If I do it as a solid color, I can get the image to display. Here’s my current CSS;
div {
background: linear-gradient(180deg, rgba(224, 34, 153, 1) 0%, rgba(88, 0, 55, 1) 100%), url('path/to/image/png') no-repeat;
}
Any way to make this work without the addition of another div?
2
Answers
solution as commented:
background-blend-mode: overlay
and optionally fiddle with thergb()
color opacity value to fine-tune the end result. Depending on the required end result, you may need to swap the image and gradient in thebackground
definition as the order does matter.extra
To test the solution myself, I created a fun demo to demonstrate the difference between the original order versus the image and gradient getting swapped.
As you can see in the demo, I used
background-image
instead of the shorthandbackground
property. This will help code optimization when you want to reuse or vary on the background definition.Lastly, as background color I used the complementary color of the gradients purple to demonstrate a
background-blend-mode
with a delimited list of different blend modes (see.grad4
and.grad5
).bonus
Make sure to enable
[class*="grad"] { background-attachment }
and see what happens when the browser window gets resized…snippet