How do I make the div maintain its background color? I added a red-white gradient to show what I mean. When its background is colored it works as-is on top of the background image. However, once I set it to white the background image bleeds through and the div apparently becomes transparent.
I have tried setting the opacity for the div, changing the z index as well. It's my first time using mask-image so ik that is causing it, I just am not sure how to make it work.
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
}
img {
width: 100%;
margin-bottom: -150px;
mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
-webkit-mask-image: linear-gradient(
to bottom,
rgba(0, 0, 0, 1),
rgba(0, 0, 0, 0)
);
z-index: -1;
}
#d > div {
margin: auto;
margin-top: 20px;
width: 80%;
height: 300px;
background: linear-gradient(to right, red, white 50%);
border: 1px solid;
z-index: 1;
}
</style>
<body>
<div id="d">
<img
src="https://m.media-amazon.com/images/I/71DsjJ9hF9L._SX3000_.jpg"
alt=""
/>
<div></div>
</div>
</body>