Skip to content

[css-position] Relative position treats percentages in the block axis as cyclic #9353

@Loirooriol

Description

@Loirooriol

https://drafts.csswg.org/css-position-3/#valdef-top-percentage

The inset is a percentage relative to the containing block’s size in the corresponding axis (e.g. width for left or right, height for top and bottom).

As far as I know, shifting the position of an element with relative positioning can't affect the size of the containing block (other than by triggering scrollbars, which is addressed in CSS Overflow). So these percentages should be able to resolve against the final size of the containing block as per the spec just fine.

However, there is interoperability that these percentages are considered cyclic and behave as auto if the containing block doesn't have a definite size during intrinsic sizing, and aren't re-resolved after the size of the containing block is known. That is, same behavior as percentages in block-size (https://drafts.csswg.org/css-sizing-3/#non-replaced-percentage-contribution).

Example:

<div style="display: inline-block; border: solid; margin-top: 50px">
  <div style="width: 100px; height: 100px; position: relative; top: 50%; bottom: 50px; left: 50%; right: 50px; background: cyan"></div>
</div>
<div style="display: inline-block; width: 100px; height: 100px; border: solid; margin-top: 50px">
  <div style="width: 100px; height: 100px; position: relative; top: 50%; bottom: 50px; left: 50%; right: 50px; background: magenta"></div>
</div>

Should all browser try to change, or update the spec to reflect reality?

(Initially discussed in #9267, but orthogonal to that issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Agenda+ LaterLower-priority items that are flagged for CSSWG discussioncss-position-3Current Work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions