Skip to content

[css-values-4] Allow combining number and percentage #7485

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

Closed
cdoublev opened this issue Jul 11, 2022 · 1 comment
Closed

[css-values-4] Allow combining number and percentage #7485

cdoublev opened this issue Jul 11, 2022 · 1 comment

Comments

@cdoublev
Copy link
Collaborator

In CSS Values 4, 10.9. Type Checking:

Note: In previous versions of this specification, multiplication and division were limited in what arguments they could take, to avoid producing more complex intermediate results (such as 1px * 1em, which is <length>²) and to make division-by-zero detectable at parse time. This version now relaxes those restrictions.

[...]

Note that <percentage>s relative to <number>s, such as in opacity, are not combinable with those numbers — opacity: calc(.25 + 25%) is invalid. Allowing this causes significant problems with "unit algebra" (allowing multiplication/division of <dimension>s), and in every case so far, doesn’t provide any new functionality. (For example, opacity: 25% is identical to opacity: .25; it’s just a trivial syntax transform.)

Is the second note obsolete or is there a reason not to allow combining <percentage> and <number> when <percentage> is resolved relative to <number>?

@tabatkins
Copy link
Member

The note is still valid, and in fact was written after adapting calc() to handle unit algebra. Allowing %s to resolve to an empty type (like numbers) would make a lot of definitely-invalid calculations appear possibly-valid, and you wouldn't know they aren't until you actually resolved the percentage's type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants