How can I build something like below using css? I want to have a diamond cut-out of an image that does always follow the color of the background.
In short, CSS overlay effects are achieved by using the following: background-image and background CSS properties to add image and linear-gradient overlay effect. position:absolute , top , bottom , right , left CSS properties to control the position of overlay image or text.
Make sure the image fills the header, either by using height: 100%, width: 100%, or by using object-fit: cover. Set the background to your desired colour.
Use two <div> elements for the original image and overlay image. Add another <div> for the overlay image inside the second one.
CSS image overlays are a common technique for transposing text or images over each other. For example, you can combine images and text on a website when captioning an image, or place a live text element over a button. CSS image overlays can be a solid color, a gradient, a color block with transparency, or a blur.
What I want to add to Lloan's answer: If you want the images to stay with the orientation they had and simply cut out a diamond shape out of them, you'll need to do things slightly different.
In the example below, square is the diamond shape that is visible. Pic is nested in there so that 'square' can properly cut off the edges of the image that is used. This way, we can rotate the "square" to be a diamond, and rotate the picture back to it's original orientation.
body {
/* To show the background color is no problem here */
background-color: #efefef;
}
.square {
width: 100px;
height: 100px;
margin: 25px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
overflow: hidden;
}
.pic {
background: url(http://placekitten.com/g/150/150);
width: 150px;
height: 150px;
margin: -25px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class="square">
<div class="pic">
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With