Comments (5)
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
from csswg-drafts.
Strawman proposal: clip-path-mode: invert
?
from csswg-drafts.
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 px1 py1, px2 py2, ... pxn, pyn
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 0 0, 100% 0, 100% 100%, 0 100%
- 4 extra points so far), duplicate the first corner's coordinates after that (in this case 0 0
- 5 extra points), drop in the inner shape points from before and duplicate the coordinates of the first shape point at the end (px1 py1
- 6 extra points). This is valid for any n-point shape.
For circles/ ellipses, regardless of whether they're inner or outer ones, I've never bothered with clip-path
.
polygon()
just isn't the best choice or curves save for rounded corners on polygons (examples: one, two) and even then just because we don't have anything better.
path()
only accepts px
, which makes it completely useless if we want to have anything responsive.
So I've always used a radial-gradient()
mask. Something like:
mask: radial-gradient(var(--r), #0000 100%, red)
This produces a jagged circle, but it can be smoothed out with a 1px
transition between fully transparent and opaque.
from csswg-drafts.
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 polygon()
from csswg-drafts.
Strawman proposal:
clip-path-mode: invert
?
I wouldn't necessarily introduce a separate property for that but just add this keyword to clip-path
.
If the need to set it separately from the shape arises, we might still introduce a longhand for it later on and turn clip-path
into a shorthand.
Sebastian
from csswg-drafts.
Related Issues (20)
- [css-mixins] `<combinator>` is already defined in Selectors HOT 1
- [css-mixins] `<dashed-function>` syntax seems invalid HOT 2
- [css-mixins] Disallow whitespace when matching `'<' transform-list '>'` HOT 2
- [css-mixins] Should `result` be mandatory in `@function`? HOT 1
- [css-filter-effects-1] Missing definition of a reference for percentage values if filterUnits="userSpaceOnUse" HOT 3
- [css-fonts] Font fallback for (Unicode) decomposable characters is browser-dependent HOT 1
- [selectors] Parameterized selectors HOT 16
- [css-view-transitions-2] (feature) access view-transition snapshot as an image/ImageData HOT 6
- [scroll-animations] Allow smooth animation from lvh to svh
- [web-animations] how to make animate() method work with CSSKeyframesRule object? HOT 4
- [css-color-5]: Relative Colors doesn’t work with `calc(l + 10%)` HOT 1
- [css-color-5]: light-dark() doesn’t work with Relative Colors HOT 2
- Two "variants" of `color-mix()` ?? HOT 3
- [css-animations-2][web-animations-2] (proposal) Add pointer driven animations
- [css-values-5] Should `interpolate-size` be a new value to animation/transition-behavior? HOT 4
- CSS Color; light-dark() should be applicable on more properties. HOT 6
- [css-color-4] Evaluate static gamut mapping algorithms for oklab/oklch spaces HOT 3
- [css-easing-2] Linear easing function requires at least two points?
- [scroll-animations-1] Consider adding a timeline range that takes ink overflow into account
- [scroll-animations-1][css-animations-1] A non-animated "Is in viewport"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csswg-drafts.