-
Notifications
You must be signed in to change notification settings - Fork 669
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
[css-values] Function to retrieve index of element among siblings, or counter on element as integer #1869
Comments
What would happen in:
? |
The second one would overwrite the first value. A way around this would be to allow other letters besides n |
I think allowing .foobar {
counter-reset: n;
}
.foobar > * {
counter-increment: n;
grid-row: counter(n integer);
} |
Having not known of counters before this, that is cool. Now, yes I believe that that is a much better way of addressing this problem |
An integer-returning If you want the index of an ancestor element to use in a further descendent, you just need to (a) register a custom property to have a |
If a specific |
The idea of a selector as well is cool but another way to get the parent's sibling count would be |
This, along with a way to get the number of children in an element, would be really nice for staggered animations. .parent {
--parent-children-count: children-count();
}
.parent .anim {
/* Stagger from start to end */
animation-delay: calc(sibling-index() * 100ms);
/* Stagger from end to start */
animation-delay: calc((var(--parent-children-count) - sibling-index()) * 100ms);
} (@Nokel81 maybe the above shows that you don't need a special way to get values from the parent) |
My entire Splitting.js library is based around giving these values as CSS variables. I would love for my library to become obsolete (though that would also require
My thoughts on the syntax would be:
Using
You can also calculate "distance" from the end (as @jakearchibald showed), or even calculate from the center (example using CSS Variables] |
It seems like the newer issue, #4559, has more traction. Maybe this should close? |
Yeah, since #4559 is the version that actually got a WG resolution, I'll close this one. |
Currently you can write the following with the
:nth-child
or similar style selectorsWhich means that every second child has a background colour of lime. However you cannot do something like the following:
I think that this would be very useful and would make working with grids quite a bit more easy
The text was updated successfully, but these errors were encountered: