I am trying to create a rectangle masking div with variable width and height. An image overlapped with a rectangle div, inside of the rectangle should preview the background image and outside of the div is filled with transparent background color. I have attached an image to clarify my concern.
For example, I have found below code from w3schools. It is created with a circle overlapped masking. In my case masking should be in rectangle and the rectangle size and positions may vary. Please suggest me a better solution!
.mask2 {
-webkit-mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
mask-image: radial-gradient(circle, black 50%, rgba(0, 0, 0, 0.5) 50%);
}
<div class="mask2">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="600" height="400">
</div>