<div class="image-box" style="--image-url: url(https://picsum.photos/3000/2000)">
<h1>Buy our product</h1>
</div>
.image-box {
/* Here's the trick */
box-shadow: inset 0 0 0 100vw rgba(0,0,0,0.5);
/* Basic background styles */
background: var(--image-url) center center;
background-size: cover;
/* Here's the same styles we applied to our content-div earlier */
color: white;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
/* Add a transition, just for fun */
transition: box-shadow .3s ease-out;
}
.image-box:hover {
box-shadow: inset 0 0 0 100vw rgba(0,0,0,0.2);
}
/* For demo only */
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
h1 {
font-size: 40px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.