Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create diamond overlay image using css [closed]

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.

Diamond overlay

like image 541
Jeg Bagus Avatar asked Jun 23 '13 06:06

Jeg Bagus


People also ask

How do you add an overlay to an image in CSS?

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.

How do you color overlay in CSS?

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.

How do you make two images overlap in CSS?

Use two <div> elements for the original image and overlay image. Add another <div> for the overlay image inside the second one.

What is image overlay in CSS?

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.


1 Answers

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>
like image 160
Sumurai8 Avatar answered Oct 20 '22 09:10

Sumurai8