Skip to content

[css-sizing-3] Mapping HTML’s IMG aspect-ratio behavior into CSS. #4951

Closed
@fantasai

Description

@fantasai

HTML accepted to map the width and height attributes of the IMG element (and some others) to an aspect ratio for the purpose of rendering in whatwg/html#4952 . Currently this is specified as providing an “intrinsic aspect ratio” until the image loads and is able to provide its own. Since the current aspect-ratio property doesn't have a way to indicate "use this value until the element can provide its own", the behavior can't be mapped directly to CSS.

But we do prefer having rendering rules mappable to CSS, so the question is how should we make this possible? The two questions are:

  1. What syntax to use to indicate "here's an aspect ratio to use but only until the thing loads and provides its own info"?
  2. How do we handle the nuances of box-sizing? Currently an explicit aspect ratio (<ratio>) uses the specified box, whereas an intrinsic one (auto) uses content-box always. Probably the IMG mapping should continue to use content-box always. Is this a function of the above-mentioned syntax, or an extra switch?

Wrt 1, I suggest just allowing the auto and <ratio> values to be combined. (The current syntax is auto | <ratio>, this would make it auto || <ratio> with the combined value treating <ratio> as fallback only.)

Wrt 2, we could consider one or both of:

  • Combining auto and <ratio> triggers using content-box always.
  • Add an optional box-sizing keyword into the syntax, e.g. auto || <ratio> || <visual-box>.

My inclination is to do both.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions