GithubHelp home page GithubHelp logo

Comments (5)

Afif13 avatar Afif13 commented on July 17, 2024 2

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

image

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.

bramus avatar bramus commented on July 17, 2024

Strawman proposal: clip-path-mode: invert?

from csswg-drafts.

thebabydino avatar thebabydino commented on July 17, 2024

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.

Example.


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.

Examples: one, two.

from csswg-drafts.

bramus avatar bramus commented on July 17, 2024

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.

SebastianZ avatar SebastianZ commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.