How to make a CSS3 Clip Path - css

I want to make figure 1
like as figure 2
using clip path, is it possible?
thanks.

clip-path is still a very experimental CSS3 element and therefore isn't very well supported and what support there is is minimal.
Using the CSS3 clip-path element to generate the polygon only allows for straight corners as its all point based rather than allowing for curves.
Heres an example:
body {
background: #555;
margin: 0;
}
img {
-webkit-clip-path: polygon(98% 0, 100% 2%, 100% 88%, 98% 90%, 25% 90%, 20% 99%, 15% 90%, 2% 90%, 0 88%, 0 2%, 2% 0);
clip-path: polygon(98% 0, 100% 2%, 100% 88%, 98% 90%, 25% 90%, 20% 99%, 15% 90%, 3% 90%, 0 88%, 0 2%, 2% 0);
}
<img src="http://lorempixel.com/200/200/" />
Your best alternative would be to use an actual SVG element and reference it within the CSS to do the cut out. If you want a perfect shape but sadly no support on IE, this is the way to go.
SVG Only Version
body {
background: #555;
margin: 0;
}
img {
clip-path: url(#svgPath);
-webkit-clip-path: url(#svgPath);
}
<svg height="0" width="0">
<defs>
<clipPath id="svgPath">
<path fill="#FFFFFF" d="M50,0 L450,0 Q500,0 500,50 L500,400 Q500,450 450,450 L200,450 L175,500 L150,450 L50,450 Q0,450 0,400 L0,50 Q0,0 50,0z" />
</clipPath>
</defs>
</svg>
<img src="http://lorempixel.com/500/500/" />

Related

How to draw a rectangle with an angled corner in SVG

I'm using a clip path from an inline SVG to mask images with different aspect ratios on a website. The mask should hide the right bottom corner at a fixed angle (-15deg).
I cannot achieve that the right corner always stays at an angle, independently of the aspect ratio of the masked image.
My current SVG looks like this:
<svg height="0" width="0" viewBox="0 0 1 1" preserveAspectRatio="none">
<defs>
<clipPath id="clipRight" clipPathUnits="objectBoundingBox">
<rect x=0 y=0 width=1 height=0.5 />
<rect x=0 y=0.5 width=1 height=0.5 transform="skewX(-15)" />
</clipPath>
</defs>
</svg>
and the css code looks like this:
.img-clip-right {
clip-path: url(#clipRight);
}
The clip path should look like this
I there a way to draw a line at a specific angle to the bottom end of the svg canvas without knowing the exact image dimension and without using javascript?
I don't quite understand why an SVG and masking is required.
This snippet just applies the clip path to the images.
It takes a corner off at 15degrees of the same area regardless of the size or aspect ratio of the image as the amount to be taken off is not specified in the question:
.clipped {
--x: 100px;
--tan15: 0.267949192;
--y: calc(var(--tan15) * var(--x));
clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--y)), calc(100% - var(--x)) 100%, 0 100%);
}
<img class="clipped" src="https://picsum.photos/id/1015/200/300">
<img class="clipped" src="https://picsum.photos/id/1015/300/300">
<img class="clipped" src="https://picsum.photos/id/1015/300/200">
I like the idea about using SVG for clip-path, but maybe in this case a simpler solution could be ok. What about the polygon() function? Here are three examples:
body {
display: flex;
}
div {
margin: 2px;
}
div:nth-child(1) {
background: CornflowerBlue;
width: 200px;
height: 200px;
clip-path: polygon(0 0, 100% 0, 100% 80%, 80% 100%, 0 100%);
}
div:nth-child(2) {
background: Peru;
width: 200px;
height: 200px;
clip-path: polygon(0 0, 100% 0, 100% 160px, 160px 100%, 0 100%);
}
div:nth-child(3) {
background: DarkSeaGreen;
width: 200px;
height: 300px;
clip-path: polygon(0 0, 100% 0, 100% calc(100% - 40px), calc(100% - 40px) 100%, 0 100%);
}
<div></div>
<div></div>
<div></div>
You can use math to calculate the length of each triangle side, and use a <path /> instead of <rect /> to build a pentagon.
But in your question, you didn't specify the size of the white triangle, even with the same set of angles(15-90-75 in your case) it can be any size, and just scale. If you have a specific size of any triangles side, that would be a clearly determined task.

CSS Clip-Path Generator not working for me

How to fit my image in the correct position? I just straight away copy the code from CSS path maker through website. But I couldn’t resize the image from my actual image in HTML. May I know what are the codes that needed or any way to fix the image?
My Code script
.brazilimg{
background-image:url("image/brazil.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
margin-top:400px; margin-left:60px; }
[my code script][1]
[CSS Clip Path Generator][2]
My final outcome after entering the code
The original image that I want to create image clipping
Your CSS is clipping the image but the image is not centred within the div so you get just the top part. Also there is a large top margin which means you just see the top part, as shown in your image in the question. Here's the whole clipped image - as you see, just the top part.
If we add to the .brazilimg class something that tells the system to center the image within the div, clipping the right and left sides so as to maintain the image's aspect ratio, we see the correct image. background-size: cover; is what we have added.
Here is a snippet showing the problem before the image is centred, but with the large top margin commented out so we see the whole image:
.brazilimg{
background-image:url("https://i.stack.imgur.com/bUUz7.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
/*margin-top:400px;*/
margin-left:60px;
}
<div class="brazilimg"></div>
And here is a snippet with the cover added to centralise the image:
.brazilimg{
background-image:url("https://i.stack.imgur.com/bUUz7.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
/*margin-top:400px;*/
margin-left:60px;
/* added to ensure the image is centrally located */
/* and make this CSS class more general for different images' aspect ratios */
background-size: cover;
}
<div class="brazilimg"></div>

CSS geometrics - mixed shapes?

is it possible to set the shape of an image not just with either straight or rounded shapes but with a mix of both?
I want my image in a emblem shape like this:
Image
Is this possible just with css or do i need further svg/canvas?
Thanks in advance
You can use the css clip-path or mask properties with an svg. Here are some examples:
Clip Path:
.element-clip-path {
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
Mask:
.element-mask {
-webkit-mask: url(/path/to/mask.svg);
-moz-mask: url(/path/to/mask.svg);
-ms-mask: url(/path/to/mask.svg);
-o-mask: url(/path/to/mask.svg);
mask: url(/path/to/mask.svg);
}
Here is a great online tool you can use to create clip paths:
https://bennettfeely.com/clippy/

Image inside triangle css?

I'd like to achieve a custom image triangle shape with rounded corner like this using css
I looking for how achieve like this but nothing,
i want to achieve my css can do result like this,any ideas?
Sorry if my question has looks like other question
Thanks
You could use clip-path. It allows you to show only part of an element and hide the rest, so make a polygon with sufficient dots for the rounded effect at corners.
.tri {
position: relative;
width: 130px;
height: 130px;
background: url("http://pdphoto.org/images/tacos.jpg");
clip-path: polygon(1% 78%, 46% 2%, 49% 0, 54% 0, 57% 2%, 98% 78%, 98% 83%, 95% 87%, 89% 88%, 6% 89%, 2% 87%, 0 83%);
}
<div class="tri"></div>

Is it possible to make backgound repeat from bottom left corner of screen to top right?

I have some image pattern, and I want it to strike an element(e.g. body). I could create pseudo element with background and rotate it for n degree, but it's a bad solution because I don't know proportions of the block.
Any ideas how I could achieve it using CSS only?
While there isn't a CSS property that does what you want, it can be hacked in.
It's a bit ugly and it's not a real repeat, but it might work for you.
HTML:
<div class="container"></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
CSS:
.container {
width: 500px;
height: 500px;
background-image:
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png");
background-position:
0% 100%,
10% 90%,
20% 80%,
30% 70%,
40% 60%,
50% 50%,
60% 40%,
70% 30%,
80% 20%,
90% 10%,
100% 0%;
background-repeat: no-repeat;
}​
http://jsfiddle.net/z4FD3/
Here I repeated the same image 10 times. You can do it as many times as you want, just add more lines and smaller intervals between the positions (e.g.: 0% 100%, 2% 98%, 4% 96%).
why not making a pattern that will look like it goes slant like the example above

Resources