-
Notifications
You must be signed in to change notification settings - Fork 707
[css-values] Add a way to set longhands to the corresponding expansion of a shorthand value #8055
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
Hm, this definitely solves the round-trip (setting a longhand to itself) and cssText issues, but still doesn't let you reserialize the shorthand when one of the longhands is modified. If we specified which longhand was being extracted from the shorthand, rather than it being contextual from the property it's used in, we'd get around that, but it would open us up to allowing less-sensical things to be specified, like Nit: I wouldn't use |
Yes, but it's not strange that a shorthand may not be able to represent all possible values of the longhands, and it's not such a big deal, since Being able to specify which longhand to extract would offer more flexibility but it still doesn't guarantee that all shorthands will be serializable, and it opens the can of worms of using values from one property on another, which is difficult to define since some browsers normalize values at parse time by adding/removing/reordering components, which may affect whether it's still valid in the other property. Even in the same property it seems tricky if
Yes I thought about |
I have edited the top post to use |
Something that I missed is that we usually turn longhands into shorthands, so this should be allowed in shorthands as long as the referenced shorthand covers all the longhands (it's a supershorthand). So for example, in Backgrounds L3, background-position: from-shorthand(background: 10px 20px red); would behave as background-position: 10px 20px; And in L4 it becomes a shorthand so it would expand to background-position-x: from-shorthand(background: 10px 20px red);
background-position-y: from-shorthand(background: 10px 20px red); and behave as background-position-x: 10px;
background-position-y: 20px; |
|
Yeah, so far I avoided exposing this just for lack of use-case, but if the lack is confusing authors, we should def expose it. I haven't given a lot of thought to what syntax to use; we've got a few here in the thread. |
Rationale
There are some ways to set longhands to values that can't be represented at specified-value time, so they just serialize as empty string. In particular:
toggle()
values (see [css-values] toggle() for shorthands is not forward compatible #6764)This doesn't seem ideal, since we lose round-tripping (assigning empty string in CSSOM will just remove the declaration) and it's hard to tell what the value is. All these cases have in common that the value is set from some shorthand, so
cssText
can help serializing such shorthand, but this produces poor results when some longhand has been modified afterwards (see #2515):Proposal
So I had an idea to address all of this: introduce
from-shorthand( <custom-ident> ':' <whole-value>)
:from-shorthand()
is a<whole-value>
.<custom-ident>
doesn't match the name of some shorthand ASCII case-insensitively.When used on a shorthand, it's invalid if the referred shorthand is not a "super-shorthand" (i.e. it's invalid if there is a property which is a longhand of the current shorthand but is not a longhand of the referred shorthand).
<whole-value>
is an invalid value for the referred shorthand.<whole-value>
.:
since it looks clearer, like a declaration. Function arguments typically use,
but that could get confusing in case the<whole-value>
has commas. (Edited: initially suggested;
)Then:
I guess there may be compat issues in the
var()
case, but hopefully people are not relying on getting an empty string.The text was updated successfully, but these errors were encountered: