Skip to content

[css-position-3] Incorrect handling of auto inset properties in absolute positioning #11242

Open
@gitspeaks

Description

@gitspeaks

Spec References

  1. 3.5.1. Resolving Insets: the “Inset-Modified Containing Block”

    "If only one inset property in a given axis is auto, it is set to zero."

  2. 3.1. Box Insets

The initial value of top, right, bottom, or left is: auto.

  1. 4. Absolute Positioning Layout Model

Absolute positioning not only takes a box out of flow, but also lays it out in its containing block (after the final size of the containing block has been determined) according to the absolute positioning layout model:

  1. First, its inset-modified containing block is calculated, defining its available space.
  2. Next, its width and height are resolved against this definite available space, as its preferred size

Scenario

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style>
      #parent {
        position: relative;
        width: 200px;
        height: 200px;
        border: 1px solid black;
      }

      #child {
        position: absolute;
        background-color: yellow;
        top:0;
        right:0;
      }
    </style>
  </head>
  <body>
    <div id="parent">
      <div id="child">
        BOX
      </div>
    </div>
  </body>
</html>

Expected Behavior

According to the spec, the inset properties left and bottom, being exclusively auto in their respective axes, should compute to 0. This means:

  1. With top and right explicitly set to 0, the #parent div defines an inset of 0 on all sides, meaning the inset-modified containing block will match the dimensions of the absolute-position containing block (e.g #parent div).

  2. The #child div should size itself to cover the maximum available space, filling the #parent div entirely.

Actual Behavior

In both Chrome and Firefox:

  1. The #child div sizes itself to fit its inline content.
  2. Its position is aligned to the top-right edge of the #parent div padding edge.

This behavior contradicts the specification, as the unset inset properties (left and bottom) are resolved to non-zero values.

Note:

  • This behavior persists even when explicitly setting left and bottom to auto, instead of relying on their implicit initial value of auto.

  • Explicitly setting all inset properties (top: 0; right: 0; left: 0; bottom: 0;) causes the #child div to correctly cover the #parent div, showing that the behavior works as expected when no auto values are involved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions