CSS clip-path can go outside of an element (#tilPost)

I’ve been reading one of Temani Afif’s CSS magic posts and discovered a clip-path CSS trick I wasn’t aware of.
clip-path allows you to clip an element in various ways. You can use geometric shapes like circles and SVG paths. It’s pr…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I've been reading one of Temani Afif's CSS magic posts and discovered a clip-path CSS trick I wasn't aware of.

clip-path allows you to clip an element in various ways. You can use geometric shapes like circles and SVG paths. It's pretty cool!

.element {
  clip-path: circle(50px at 0 100px);
  clip-path: path(
    "M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z"
  );
}

But to be fair, I haven't used clip-path extensively, because a) my projects aren't that fancy, and b) I can't be bothered with creating complicated SVG paths.

But then there's also polygon. With polygon you can define clipping pointed with relative percentages. Handy!

.element {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

And Temani shared that you can even define points outside the 100% range, too! 😲

It’s a little known fact that clip-path accepts values outside the 0%-100% range, which allows us to create “overflowing” shapes.

This detail is something I could get my head around to create some custom corners!

[Interactive component: visit the article to see it...]

Thank you, Temani!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-11-14T23:00:00+00:00) CSS clip-path can go outside of an element (#tilPost). Retrieved from https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/

MLA
" » CSS clip-path can go outside of an element (#tilPost)." Stefan Judis | Sciencx - Monday November 14, 2022, https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/
HARVARD
Stefan Judis | Sciencx Monday November 14, 2022 » CSS clip-path can go outside of an element (#tilPost)., viewed ,<https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » CSS clip-path can go outside of an element (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/
CHICAGO
" » CSS clip-path can go outside of an element (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/
IEEE
" » CSS clip-path can go outside of an element (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/. [Accessed: ]
rf:citation
» CSS clip-path can go outside of an element (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/11/14/css-clip-path-can-go-outside-of-an-element-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.