Css overlay image

How to mask image using css form?

link

enter image description here

I already made a form with css border style, but could not overlay the image.

CSS

#triangle-topleft {
  width: 0;
  height: 0; 
  border-top: 100px solid red;
  border-right: 100px solid transparent; 
}
+4
source share
2 answers

Option 1 - SVG

<svg width="100" height="100">
  <defs>
    <pattern id="a" patternUnits="userSpaceOnUse" width="100" height="100">
      <image xlink:href="http://lorempixel.com/300/300" x="0" y="0" width="100" height="100" />
    </pattern>
  </defs>
  <polygon points="0,0 100,0 50,100" fill="url(#a)" />
</svg>
Run codeHide result

Tested in Chrome, Firefox, IE9 +


Option 2 - clip-path

.element {
  display:inline-block;
  -webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
<div class="element">
  <img src="https://s3.amazonaws.com/uifaces/faces/twitter/ok/128.jpg" />
</div>
Run codeHide result
+3
source

You can use for this gradients. Here is a sample code:

div {
  width: 100px;
  height: 100px;
  background-image: linear-gradient(to bottom left, white 50%, transparent 0),        
    url('http://lorempixel.com/100/100');
}
<div></div>
Run codeHide result

Working violin

+2
source

All Articles