Join the Webstudio community

Updated 4 weeks ago

Is there an effective way to add a gradient on an image component?

I want to have an image component which changes the image based on what the mouse focused on, but I want that there is a gradient over it. I can't use the image in a div and use backgrounds because than my function wouldn't work because I can't give the image in the backgrounds an id.
J
12 comments
Is there an effective way to add a gradient on an image component?
.img-container>img+.img-overlay

.img-container { position: relative; }
img { z-index: 0; }
.img-overlay { position: absolute; inset: 0; z-index: 1; backgound-image: linear-gradient; }

This is how you could setup the structure & styles.
so just with custom advanced css?
no, you'd apply tokens for the css
where do you find "inset" and for what use it?
https://css-test-components.wstd.io
I built this test for someone else in discord. It has the same attributes you're looking for. Do you know how to use dev tools to figure out how it's built?
header has a z-index of 2
overlay has z-index of 1
background image I didn't set the z-index or position
Attachment
CleanShot_2024-12-12_at_12.44.202x.png
got it
Attachment
image.png
I use that pattern all the time
Thank you ver much
Add a reply
Sign up and join the conversation on Discord