Skip to content

[mediaqueries][css-contain] How to evaluate <ratio> queries? #8244

@Loirooriol

Description

@Loirooriol

It seems hard for a viewport to have a degenerate ratio, so I guess @media (aspect-ratio) is mostly fine. But we have a problem for @container (aspect-ratio), there is no interoperability. Testcase

First, how should aspect-ratio be evaluated in boolean context?

Typically that checks if the condition is true for any non-zero value. Is that 0 / 1 for ratios? I'm not convinced this makes much sense, one of these options seems better:

  • Check if any ratio would evaluate to true
  • Check if any ratio different than 0 / 0 would evaluate to true
  • Check if any non-degenerate ratio would evaluate to true

Also, how to compare ratios?
I think we could say 0/a = 0/b < c/d = e/f < g/0 = h/0 for any a,b,c,d,e,f,g,h > 0 s.t. c*f = d*e.
Then the tricky part is comparing with 0 / 0.

Some proposals:

  1. We consider ratios in the [0,∞] interval, plus a special 0/0 value outside the interval. Strict inequalities between 0/0 and other ratios are false.
  2. We consider ratios in the [0,∞] interval, with 0/0 being an indeterminate value in the interval. Most comparisons with 0/0 are unknown, but some inequalities with the limits of the interval are known.
  3. Like 1 or 2, but using unknown for ratios that are not comparable, i.e. when none of =, < and > would be true.
  4. Like 3, but using unknown when comparing a degenerate ratio with itself.

I think I'm leaning towards the 1st one.

Some notes from the implemented behaviors that I have observed:

  • Evaluating min-aspect-ratio and max-aspect-ratio in a boolean context produces unknown as defined in the spec.
  • aspect-ratio: <ratio> is a synonym of aspect-ratio = <ratio>, min-aspect-ratio: <ratio> is a synonym of aspect-ratio >= <ratio>, and max-aspect-ratio: <ratio> is a synonym of aspect-ratio <= <ratio>.
  • Ratios are broken in Blink, e.g. 1 and 1 / 1 have different behaviors, same for 0 and 0 / 1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Needs Edits

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions