Skip to content

[css-grid-2] conditional subgrid fallback when no parent grid is available #6692

@mor10

Description

@mor10

Reference: https://drafts.csswg.org/css-grid-2/#subgrids

Issue:

When subgrid is used on a container whose parent does not have a grid declared, there is no way to provide alternate grid lines as a fallback. Using the cascade as in the example below does not work because even without the parent grid, the subgrid declaration is still valid.

.subgrid {
  grid-template-columns: repeat(4, 1fr); /* fallback does not work*/
  grid-template-columns: subgrid;
}

Expected behavior

Provide grid line fallbacks for subgrid when a parent grid is not present.
Example:

grid-template-columns: subgrid, repeat(4, 1fr);

Scenario

A component uses the parent grid if it is present through conditional subgrid. If the parent has a grid, the subgrid applies, otherwise the component uses its own grid lines.

Sandbox

I've built a rudimentary example to demonstrate the above scenario:
https://codepen.io/mor10/pen/ZEyVpZb

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