-
Notifications
You must be signed in to change notification settings - Fork 711
[css-anchor-1] Transitioning when the anchor element with a given name changes #8181
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
Yep – Transitioning the inset properties or being able to use those values in calc to generate working-transitions.mp4It shows a use case where you might want an element to follow user interaction. Not one I'd throw into production anytime soon 😅 But it works using :root {
--active-anchor: --email;
--active-left: anchor(var(--active-anchor) right);
--active-top: anchor(var(--active-anchor) center);
}
:root:has(.form-group:focus-within) {
--anchor-scale: 1;
--anchor-transition: top 0.2s, left 0.2s, transform 0.2s;
}
#password {
anchor-name: --password;
}
:root:has(#password) {
--active-anchor: --password;
} A combination of implicit anchor and transition could also be useful in a variety of tooltip/overlay scenarios too. Even those type trigger UI where like on here when you type UPDATE:: form {
--anchor-one: anchor(--one top);
--anchor-two: anchor(--two top);
}
.el { top: var(--anchor-one); }
form:has(#two:checked) el { translate: 0 calc(var(--anchor-two) - var(--anchor-one)); } It would look a little like that where you could use the value in a |
Disclaimer and additional linksI'm submitting my feedback following my experiments with the current implementation of anchor positioning in Chrome Canary. I wrote an article about my experiments, but decided to fill most of my feedback as separate issues here. A quick summary of related links: I'm using this issue instead of creating a new one in order not to duplicate things. The issue topic that I wanted to give — “[css-anchor-1] Transitions when moving the anchor-name”. I did experiment a bit with transitions, and found the same case that works — having multiple elements with different The experiment in question: https://kizu.dev/anchor-positioning-experiments/#transitions In my case, initially I wanted to instead change to which element the static This way the case for my transition would've been significantly simplified. Here is a CodePen with just the reproducible cases which work and which does not: https://codepen.io/kizu/pen/RwYMmmp |
I would want to provide another use-case — quite an old experiment by @NV, where it could be possible to have a transition for the focus-ring between elements — https://n12v.com/focus-transition/ If the position change that correspond to the change in focus for the |
In other words, something like a tree-scoped name, but instead of only capturing the tree-scope, it now also captures the element it's referencing? This means intermediate states would appear to interpolate to and from the same value, when serialized, right? @tabatkins Have we considered resolving |
Since my previous post raised some questions yesterday (elsewhere), I'll add a more detailed explanation, and some more thoughts on this. Container relative units (
During the regular style recalc process, after computing the style for Then, when layout reaches The above works, because at the time we finally end up resolving The same appears to be true for The new path we're on for @position-fallback also requires the same uncleanliness: we must know the computed value of Doing multiple rounds isn't a problem for the implemenation, but figuring out a decent mental model (spec) for this might require some thought ... |
Would having something like an |
@kizu I don't think so, because in that case the "ancestral container" (i.e. element holding |
Should be addressed by the current draft spec. |
@mfreed7 Is it really addressed? I see it's still an open issue in the spec. |
Thanks for raising this! You're right that this still needs work. |
It's pretty obvious that if an element changes from
top: anchor(--foo top);
totop: anchor(--foo bottom)
, that's a computed-value change that will trigger a transition on 'top'.But what happens when the value is
top: anchor(--foo top);
the whole time, but you change which element hasanchor-name: --foo;
? @jh3y has an example of this using the popover API, where they change the popover attribute, altering which element is used as the "implicit anchor element" without actually touching the CSS. They'd like the abspos to smoothly transition to its new position.I think this gets solved appropriately with the exact same solution as #8180 - if the tree-scoped reference is resolved as part of the computed value, then having it change underneath you counts as a computed-value change, thus triggering a transition, and the start and end values are (non-textually) distinct, referring to the old and new anchor, so you can meaningfully transition between them.
The text was updated successfully, but these errors were encountered: