question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS-Grid wrong ms prop values w/ media queries

See original GitHub issue

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;
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
aicommented, Dec 13, 2017

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

1reaction
aicommented, Oct 8, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

C32: Using media queries and grid CSS to reflow columns
The basic principles of grid layouts are to: Define the size of layout regions using grid properties and media queries for specific viewport...
Read more >
Concise Media Queries with CSS Grid - Thoughtbot
I've seen media queries of all varieties trying to solve the same problem. A common method is to describe a media query which...
Read more >
Look Ma, No Media Queries! Responsive Layouts Using CSS ...
The repeat() function. Generally speaking, what we usually do to define our columns and rows on a CSS Grid is to add the...
Read more >
CSS Grid Layout and progressive enhancement
A solution using feature queries ... Feature queries will look very familiar if you have ever used a media query to create a...
Read more >
Issues with CSS Grid and Media Queries [closed]
You just forgot a semicolon after your grid-template-areas in your media query. .container { display: grid; grid-gap: 1.2em; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found