Skip to content

[css-grid-2] Clamp out-of-range subgrid items before or after auto placement? #8494

Open
@KurtCattiSchmidt

Description

https://www.w3.org/TR/css-grid-2/#subgrid-implicit

The spec states:

"The subgrid does not have any implicit grid tracks in the subgridded dimension(s). Hypothetical implicit grid lines are used to resolve placement as usual when the explicit grid does not have enough lines; however each grid item’s grid area is clamped to the subgrid’s explicit grid (using the same procedure as for clamping placement in an overly-large grid).
For example, if a span 1 subgrid has a grid item with grid-column: 2 / span 3;, then that item is instead forced into (and limited to) the first (only) track in the subgrid."

This doesn't indicate when to perform the clamping, and this can have implications on placement if it happens before or after the auto placement algorithm.

Modifying the example above slightly to demonstrate this:

If a column span 1 and row span 2 subgrid has a grid item with grid-column: 2 / span 3, then that item is instead forced into (and limited to) the first track in the subgrid. Now consider if it has a second item with grid-column: 2 / span 3.

If clamping occurs before the auto placement algorithm, both items will be clamped to the first row of the subgrid. Then, auto placement will consider the overlap, and the second item will be placed in the second row.

If clamping occurs after the auto placement algorithm, both items will be placed in hypothetical implicit lines during auto-placement and will not overlap during placement. However, once they're clamped (after auto placement), the implicit lines go beyond the subgrid span, so the first and second items will be placed in the first row of the subgrid (and will occupy the same space).

The intention of auto placement seems to be to avoid items occupying the same space, so it does make sense to perform clamping before auto placement (so that out-of-range items do not overlap). However, the spec is ambiguous here.

Note that Firefox and Safari's behavior is to clamp before auto placement. Chromium used to clamp after auto placement, until I changed it recently to fix a subcase of http://wpt.live/css/css-grid/subgrid/repeat-auto-fill-001.html. I also added a WPT test that hits this scenario (http://wpt.live/css/css-grid/subgrid/placement-implicit-001.html).

Metadata

Assignees

No one assigned

    Labels

    css-grid-2Subgrid; Current Work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions