simple css grid not working on IE11

家住魔仙堡 提交于 2020-07-09 13:08:47

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/49025133/simple-css-grid-not-working-on-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!