-
Notifications
You must be signed in to change notification settings - Fork 672
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
[selectors][css-transitions-2] :starting-style
pseudo-class
#10356
Comments
starting-style
pseudo-class:starting-style
pseudo-class
Tagging in @josepharhar and @mfreed7 for your thoughts on this and the current implementation (Also want to bring up the usecase where the entry and exit animation are different for consideration) |
I agree that using a pseudo-class instead of an at-rule would be better for deduplication of style rules. This was decided here: #8174 It looks like the original proposal was a pseudo-class but was changed to an at-rule. I'm not sure if it was due to developer ergonomics, restrictions on what you can put inside of the pseudo-class, ease of implementation/spec, or some combination of the 3. |
Either of these proposals would resolve this issue if resolved as accepted by the CSSWG:
Thanks, @argyleink, for telling me about #6247. |
The first prototype used a pseudo-class. I think the discussion starting from #8174 (comment) may be informative as to how we ended up with the at-rule. I think one of the big reasons to move away from that was that it was really confusing what things like I agree that we ended up with a solution that requires a bunch of repetition that I'm not happy about. I wonder if a pseudo-element might have been a better balance. That was the one of the three things discussed that never got prototyped... |
(In slightly more detail as to the concern I mentioned: is |
@dbaron Thanks for the extra context! That helps to understand. I think the most compelling example to me so far is this one, which aligns with the logic proposed in #6247: dialog {
&, &[open]:starting-style {
transform: translateY(-50%);
&, &::backdrop {
transition: all 0.25s ease-out allow-discrete;
opacity: 0;
}
}
&[open] {
transform: translateY(0);
&, &::backdrop {
opacity: 1;
}
}
} I've left a comment on that ticket context related to To answer your question about These—on the other hand—would not, as some of the styles exist under the /* Example 1 */
div:starting-style {
background-color: blue;
p {
/* some styles */
}
}
/* Example 2 */
div {
background-color: blue;
p:starting-style {
/* some styles */
}
} |
So I think this is a core part of the problem. I don't think there's any other CSS pseudo-class for which that is the case, and I think that answer is a pretty clear sign that this isn't a pseudo-class. (But it still might be a pseudo-element.) |
@dbaron I meant to include another example which I would parallel this to. When using an at-rule, you’re usually matching selectors based on the state of an upper scope, usually the document. In that way, these two are like, as they both match a selector based on an upper-scope state: a { @media screen { … } }
b { a & { … } } Similarly, both of these pseudo-classes do the same: a:media(screen) { … }
b:is(a *) { … }
By that reasoning, I would argue that there are in fact pseudo-classes that operate near identically to that one, where |
They don't, the former prevents
|
@Loirooriol I should have provided the sample DOM structure for my example. My apologies. For this exact & specific sample DOM structure: <html>
<body>
<div class="a">
<div class="b">…</div>
</div>
</body>
</html> Both Generally speaking, the two selectors clearly have different meanings and cannot be used interchangeably. The general idea I am attempting to demonstrate is that a |
Related specifications & authors
Introduction
I've received valuable feedback regarding the complexity of an
--open
switch I used to demonstrate@starting-style
(shown below), which I employed to avoid redundant styles.This way, I could set up my styles in one place and control the open/closed state via a single variable. However, as I added more styles to my state, I found myself having to duplicate them into
@starting-style
each time.Problem Statement
While
@starting-style
is undeniably powerful and allows for granular control, it often requires redundancy even for simpler use cases. Consider the following example, the same as above but without the variable trick:In this example, the closed-state styles are duplicated inside
@starting-style
. This duplication becomes more apparent when animating from a custom set of closed-state styles to the default open-state styles:The styles inside
@starting-style
are often the same as the closed state but must still be duplicated for the engine to recognize them. This is where I believe there is an opportunity to simplify the process.Proposed Solution
I propose introducing a pseudo-class counterpart to
@starting-style
to eliminate the need for duplicating styles:This syntax informs the engine about the state it is animating from without requiring the developer to duplicate styles. If we want to set styles for the open state as well, we can do so like this:
Conclusion
By introducing a pseudo-class
:starting-style
counterpart to@starting-style
, we can avoid requiring developers to redeclare styles "before-state" styles inside@starting-style
. This proposal aims to improve the developer experience and make@starting-style
more approachable for simpler use cases while retaining its power and flexibility for more complex scenarios.Some related notes re CSS Mixins (TL;DR: they don't solve this problem)
While CSS Mixins will simplify the process of managing styles for different states, I believe this enhancement would be most valuable as an addition to
@starting-style
itself, included in theselectors
spec. It provides a more straightforward solution for common use cases, reducing redundancy in CSS code and making it easier for developers to define and manage animations between states.The below examples all assume these mixins are present:
Even using CSS Mixins, the mixins would still need to be invoked again within
@starting-style
:Now, with
:starting-style
and mixins:The text was updated successfully, but these errors were encountered: