-
Notifications
You must be signed in to change notification settings - Fork 716
[css-masking] Inverse clip-path #10445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Strawman proposal: |
The number of points of the shape inside shouldn't really affect the extra points needed to cut it out of the rectangular shape. Suppose the list of coordinates creating the n-point shape inside is To cut it out of the element's rectangle you need to add in extra the four corners of the rectangle going either clockwise or the other way, starting from whichever corner's closer to the start point of the shape inside (let's say For circles/ ellipses, regardless of whether they're inner or outer ones, I've never bothered with
So I've always used a
This produces a jagged circle, but it can be smoothed out with a |
Here is a generic demo from my lastest article. All you have to do is to define the main shape as a variable and you get the cut-out version: https://codepen.io/t_afif/pen/gOJvdav It's basically what @thebabydino already said but I am also playing with the reference-box to easily control the space and also using "evenodd" to avoid issues related to the order of points |
The "all you have to do" part is what I'm aiming to simplify here. It's not that easy for "regular" authors to do. The solution would also play nice with all clip-paths, not just those that use |
I wouldn't necessarily introduce a separate property for that but just add this keyword to Sebastian |
This needs more attention, browser support will become a concern everytime we need a new feature. |
Maybe we need a Basic Shape that is a |
While a |
There are no rounded corners in any of these cases, and actually rounding corners can be even trickier. Even in the mask attribute, it's almost impossible to do it in pure CSS, and needs to be done in conjunction with SVG. https://codepen.io/yisi/pen/BagqKNq?editors=0100 2024-09-02.22-21-35.mp4I would also expect to be able to support syntax like In addition, in my scenario, wouldn't it be better not to use CSS Maybe we need a new @smfr I look forward to your suggestions. |
This looks like a use case for |
Here’s an author request spotted in the wild for this: https://x.com/mattgperry/status/1896929274856427550
|
When applying a clip-path it is sometimes wanted to do an inverse clip path to cut out a hole of something. To do that today, you need to get creative with positioning the points in a polygon, as detailed in https://css-tricks.com/cutting-inner-part-element-using-clip-path/ from 2015.
Take this revealing rectangle that opens up from the center, using 4 points in a polygon:
To invert that, you need this path which requires 8 points and then animate the 4 inner points:
Demo: https://codepen.io/bramus/pen/gOJXzrq/dda132b7b26b1236da82724053ac1643
For more complicated shapes such as an opening square/rectangle you need 10 points. And for some other shapes like a circle it’s not really possible as that requires script to calculate the inverse path and you’d need a whole bunch of points in order to get a smooth shape.
Ideally, an author would be able to reuse an simple shape – such as a circle – and invert that through other means. Masks for example have
mask-composite: exclude
. Maybe we can have something similar forclip-path
?The text was updated successfully, but these errors were encountered: