Skip to content

[css-grid] Allow 0 as first argument to repeat() #9371

@vrugtehagel

Description

@vrugtehagel

This proposal is rather simple; I'd like to allow 0 as a first argument to repeat(). The spec defines the argument to be <integer [1,∞]>. Can we loosen it to <integer [0,∞]>? The primary use-case for this is when using custom properties for the amount of rows or columns in a grid. For example:

.grid {
    --column-amount: 3;
    --first-column-width: 200px;
    --default-column-width: 1fr;
    display: grid;
    grid-template: auto
        / var(--first-column-width) repeat(calc(var(--column-amount) - 1), var(--default-column-width));
}

This example breaks when setting --column-amount: 1, but it doesn't have to.

Although the use-case is admittedly relatively niche (yet I believe not insignificant), it seems to be very low-cost to allow this.

Semi-formally, repeat(0, ...) just ends up being ignored in the declaration. So, auto repeat(0, 1fr) 200px would be equivalent to auto 200px.

Metadata

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