Solution 1 - using gatsby-image
You can solve this problem using position: relative/absolute
like this:
import Img from "gatsby-image"
const Wrapper = styled.div`
position: relative;
/* width, height */
`
const Gradient = styled.div`
position: absolute;
inset: 0 0 0 0;
background: linear-gradient(/* your linear-gradient */);
`
const Text = styled.p`
position: absolute;
inset: /* position */
`
const Component = () => {
return(
<Wrapper>
<Img fluid={fluid} />
<Gradient />
<Text>Gradient over image, text over gradient</Text>
</Wrapper>
)
}
or, as proposed above:
Solution 2 - using gatsby-background-image
What has worked for me is to place a <div>
on top of the <BackgroundImage>
, and then set background: linear-gradient()
on that <div>
:
import BackgroundImage from "gatsby-background-image"
const Wrapper = styled.div`
width: /* your width */;
`
const Gradient = styled.div`
height: /* your height */;
background: linear-gradient(/* your linear-gradient */);
`
const Component = () => {
return(
<Wrapper>
<BackgroundImage ...>
<Gradient>
<p>Gradient over image, text over gradient</p>
</Gradient>
<BackgroundImage>
</Wrapper>
)
}