How to cut away part of an image or container diagonally using CSS?
The part that needs to be cut away has the form of a triangle
To be more specific: if the above picture is the image the blue part should be cut out, not the yellow
The html should be:
<figure>
<img src="img_pulpit.jpg" alt="The Pulpit Rock">
</figure>
or:
<div class="container">
content
</div>
There is from my own investigation a lot of ways to do this, but most of them is hacky, so looking for a best approach
Min browser support: IE11, latest webkits etc.
-You can use http://cssplant.com/clip-path-generator for this. It's just a "dirty solution", the best way is placing a svg above the img. Maybe in a future, the "clip css property" would support another kind of shapes than just "rect" and things like this could be done!
You could use CSS3 transform skewY() function with positive value for the parent and negative value for the child wrapper element to achieve the effect.
So, to draw a diagonal line in CSS, we have to simply rotate a normal horizontal line at an angle of + or – 45 degrees. The rotation in CSS is done using the transform property. To create a horizontal line you can either use the border-top or the border-bottom property whichever best suits you.
Use CSS3 -clip-path
and polygon
like this. You can specify whatever path you want to.
img {
width: 100px;
height: 100px;
-webkit-clip-path: polygon(0 0, 0 100px, 100px 80px, 100px 0);
clip-path: polygon(0 0, 0 100px, 100px 80px, 100px 0);
}
<img src="https://picsum.photos/id/0/100/100">
http://jsfiddle.net/r3p9ph5k/
For some extra bits you might want to take a look at e.g. this. Also, for more information about IE, see this.
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