autoprefixer icon indicating copy to clipboard operation
autoprefixer copied to clipboard

[css-grid] grid-gap warning needlessly appearing

Open Dan503 opened this issue 6 years ago • 5 comments

I have this grid code:

.grid {
    display: grid;

    /* This is producing a warning in Autoprefixer. */
    /* This code works perfectly in IE though. */
    grid-gap: 30px;
}

@media (min-width: 601px) {
    .grid {
        grid-template:
            "a    b" auto /
             1fr  1fr;
    }
}

@media (max-width: 600px) {
    .grid {
        grid-template:
            "a" auto
            "b" auto /
             1fr;
    }
}

.a { grid-area: a; }

.b { grid-area: b; }

Both the grid template declarations are wrapped in media queries. The grid gap is a default that applies to both.

This code works fine in IE with Autoprefixer so there should not be any warning given.

Dan503 avatar Apr 10 '19 02:04 Dan503

https://github.com/postcss/autoprefixer/blob/2471de84d0596778a38c915c2e70c47945aad92c/lib/hacks/grid-template.js#L44

easbarba avatar Apr 23 '19 23:04 easbarba

Recognise that this is just an edge case. I'm not endorsing the removal of the warning all together. Only for this particular scenario.

The warning can be worked around by using one of the template declarations as a default and then overide it with a media query. (It just made my code a bit messier than I would have liked).

Dan503 avatar Apr 24 '19 04:04 Dan503

FYI it’s possible to have a width of 600.5px where neither media query would apply.

casey6 avatar May 28 '19 22:05 casey6

I've never really had an issue with that.

Browser support for the new style of media queries (the ones with greater and less than symbols) isn't good enough to rely on those yet.

Dan503 avatar May 28 '19 22:05 Dan503

It’s definitely an edge case, but I’ve ran into that bug in the past. Slightly off-topic, but I felt it was worth mentioning because the warning is technically still valid in your example.

casey6 avatar May 28 '19 22:05 casey6