Tomer
Tomer

Reputation: 17940

simple css grid not working on IE11

I'm experimenting with css grid and i'm trying to make a simple example, but it does not seem to work on IE11 although i use the appropriate syntax:

.grid {
  background: gold;
  height: 90vh;
  display: -ms-grid;
  display: grid;
  grid-gap: 20px;
  -ms-grid-columns: 405px 1fr;
  grid-template-columns: 405px 1fr;
  grid-template-rows: 1fr;
  -ms-grid-rows: 1fr;
}

section {
  background: red;
}
<div class="grid">
  <section>
    section1
  </section>
  <section>
    section2
  </section>
</div>

Upvotes: 1

Views: 6809

Answers (1)

Tomer
Tomer

Reputation: 17940

Apparently you need to explicitly set the location of each element of the grid, so for the example in the question, you'll need to do this:

<div class="grid">
  <section class="s1">
    section1    
  </section>
  <section class="s2">
    section2
  </section>
</div>

.s1 {
  padding: 20px;
  background: red;
  -ms-grid-row: 1;
  -ms-grid-column: 1;

}

.s2 {
  padding: 20px;
  background: green;
  -ms-grid-row: 1;
  -ms-grid-column: 2;

}

Doing it manually can be very tedious, but if you use grid-template-areas, autoprefixer will automatically render it for you.

So the final example looks like this:

.grid {
  grid-template-areas: "s1 s2";
  background: gold;
  height: 500px;
  display: -ms-grid;
  display: grid;
  grid-gap: 20px;
  -ms-grid-columns: 405px 1fr;
  grid-template-columns: 405px 1fr;
  grid-template-rows: 1fr;
  -ms-grid-rows: 1fr;
}

.grid .grid{
    height: 300px;
}

.s1 {
  padding: 20px;
  background: red;
  -ms-grid-row: 1;
  -ms-grid-column: 1;
  grid-area: s1;
}

.s1 .s1 {
  background: teal;
}

.s2 {
  padding: 20px;
  background: green;
  -ms-grid-row: 1;
  -ms-grid-column: 2;
  grid-area: s2;
}

.s2 .s2 {
  background: yellow;
}

section section {
  background: green;
}
<div class="grid">
  <section class="s1">
    section1    
  </section>
  <section class="s2">
    <div class="grid">
      <section class="s1">
    nested-section1    
  </section>
  <section class="s2">
    nested-section2
  </section>
    </div>
  </section>
</div>

Upvotes: 2

Related Questions