autoprefixer: CSS-Grid wrong ms prop values w/ media queries

Description When a container with display: grid; changes the grid-template-areas property in a media query, children with a grid-area property will end up with values for -ms-grid-row, -ms-grid-column and -ms-grid-column-span that correspond to whichever grid-template-areas comes first, any other instances are ignored resulting in wrong placement.

Expected or desired result Depending on whether you consider this a bug, an oversight or a feature request 😉

Children with a grid-area property should be rendered once inside a new media query for each time its parent’s grid changes with MS values corresponding to these new grid values.

Example I don’t know how to add the grid: true config option to CodePen’s Autoprefixer so unfortunately, you’re going to have to try this example locally. Here’s a link to the pen anyway, in case anyone knows.

If you let Autoprefixer transpile the following code you’ll notice that the third box will have only received -ms- property values for the 768px media query and that it will still span two columns and be on a second row which no long exists above 1200px.

<div class="container">
  <div class="box boxFirst">First box</div>
  <div class="box boxSecond">Second box</div>
  <div class="box boxThird">Third box</div>
</div>
@media screen and (min-width: 768px) {
  .container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "boxFirst boxSecond"
      "boxThird boxThird";
  }
}

@media screen and (min-width: 1200px) {
  .container {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "boxFirst boxSecond boxThird";
  }
}

.box { padding: 16px; text-align: center; color: white; font-family: sans-serif; }

.boxFirst { grid-area: boxFirst; background-color: #90afc5;  }
.boxSecond { grid-area: boxSecond; background-color: #2a3132; }
.boxThird { grid-area: boxThird; background-color: #763626; }

After transpilation:

.boxThird {
  background-color: background-color: #763626;
  -ms-grid-row: 2;
  -ms-grid-column: 1;
  -ms-grid-column-span: 2;
  grid-area: boxThird;
}

Expected after transpilation:

@media screen and (min-width: 768px) {
  .boxThird {
    background-color: background-color: #763626;
    -ms-grid-row: 2;
    -ms-grid-column: 1;
    -ms-grid-column-span: 2;
    grid-area: boxThird;
  }
}

@media screen and (min-width: 1200px) {
  .boxThird {
    background-color: background-color: #763626;
    -ms-grid-row: 1;
    -ms-grid-column: 3;
    -ms-grid-column-span: 1;
    grid-area: boxThird;
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Released in 7.2.3. @evgeny-petukhov was really quick in solving this issue.

@Seanom wait next minor update. We will release big Grid update which could fix it

For temporary solution you need to put them in that same media query

Thanks for the quick work!

Might be worth mentioning somewhere that this solution requires the elements that you want to position within the grid and their parent, to be located under the same media query and that the grid-area property has to be declared again for every child each time you change the grid in the parent.

My test website broke (layout was messed up and autoprefixer warning that grid areas couldn’t be found) so I had to figure it out by looking at the changes in the commit.

Here’s the code that didn’t work, I’m using Stylus with the Rupture plugin for media queries:

.parent
  display grid
  +above(768px)
    grid-template-columns 1fr 1fr
    grid-template-rows auto auto
    grid-template-areas \
      'boxFirst boxSecond' \
      'boxThird boxThird'
  +above(1200px)
    grid-template-columns 1fr 1fr 1fr
    grid-template-rows auto
    grid-template-areas \
      'boxFirst boxSecond boxThird'

.boxFirst
  grid-area boxFirst

.boxSecond
  grid-area boxSecond

.boxThird
  grid-area boxThird

Yes, I’ll fix it. @ai How do you think what tests can cover this situation? I want to fully support media query, and insert different positions for different media (like the example in issue), but it’s not a hotfix, it needs more time.