后备css网格不起作用

时间:2018-04-30 03:22:51

标签: html css

我建议通过以下方式通过“@support”组合css-grid和css-table:支持网格的浏览器应该使用网格,不支持网格的浏览器会回退到默认的表格式。

现在看来,我的网格布局无法建立,即使ff响应@support(例如,两个链接中的一个,谁应该更改网格模式更改)。有人知道我的代码有什么问题吗?

这是我仍然得到的东西

[DEFAULT TABLE FALLBACK](https://i.stack.imgur.com/bfQNl.jpg

这就是我想要的东西

[所需的网格布局](https://i.stack.imgur.com/C5v4v.jpg

1 个答案:

答案 0 :(得分:0)

.wrapper-of-wrapper { display: none;}开始之前添加了@supports。 我想这会对你有所帮助:



html {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  display: table;
  table-layout: fixed;
  position: relative;
}

body {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

@media only screen and (max-width: 600px) {
  /*some definitions */
}

.grid-G-and-H {
  display: none;
  max-height: 0;
  overflow: hidden;
  mso-hide: all;
}

.wrapper-of-wrapper {
  display: none;
}

/*- - - - - - - - @supports - - - - - - - - - - - - */

@supports (display: grid) {
  html {
    box-sizing: border-box;
  }
  .wrapper-of-wrapper {
    position: fixed;
    width: 100%;
    height: 100%;
    display: flex;
    flex-flow: column nowrap;
    justify-content: center;
    bottom: 0;
  }
  .wrapper {
    height: auto;
    display: grid;
    -ms-grid;
    -ms-grid-columns: 16% 16% 16%;
    -ms-grid-rows: 10% 10% 10%;
    flex: 0;
    grid-column-gap: 7px;
    grid-row-gap: 7px;
    grid-template-columns: 16% 16% 16%;
    justify-content: center;
    /*horizontal*/
    align-content: center;
    /*vertical*/
    grid-auto-flow: row dense;
  }
  .box {
    justify-content: center;
    align-items: center;
    background: grey;
  }
  img {
    max-width: 90%;
    height: auto;
    margin: 5px;
  }
  .a {
    grid-column: 1 / span 2;
    grid-row: 1 / span 2;
    border: 5px solid red;
  }
  .b {
    grid-column: 3;
    grid-row: 1;
  }
  .c {
    grid-column: 3;
    grid-row: 2;
  }
  .d {
    grid-column: 1;
    grid-row: 3;
  }
  .e {
    grid-column: 2;
    grid-row: 3;
  }
  .f {
    grid-column: 3;
    grid-row: 3;
  }
  .grid-G-and-H {
    display: block;
  }
  @media only screen and (max-width: 600px) {
    /*some definitions*/
  }
}

<div id="G">
  <!--absolute positioned-->
  <a href="link.html"><img style="margin: auto; width: 23px; height: 27px; left: 20px; position: absolute; top: 0pt; bottom: 0pt;" src="http://via.placeholder.com/23x27"></a>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div>
  <a href="link.html"><img style="max-width: 600px; max-hight: 400px; width: 65%; height: auto; border: 5px solid red" src="http://via.placeholder.com/600x400"></a>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="H">
  <!--absolute positioned-->
  <a href="link.html"><img style="margin: auto; width: 23px; height: 27px; right: 20px; position: absolute; top: 0pt; bottom: 0pt;" src="http://via.placeholder.com/23x27"></a>
</div>
<!-- ## END OF DIVS FOR TABLE###### -->
<!-- ## BEGINNING OF DIVS FOR GRID ## -->
<div class="grid-G-and-H">
  <div id="G_grid">
    <a href="changed-link.html"><img style="margin: auto; width: 23px; height: 27px; left: 20px; position: absolute; top: 0pt; bottom: 0pt;" src="http://via.placeholder.com/23x27"></a>
  </div>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div class="wrapper-of-wrapper">
  <div class="wrapper">
    <div class="box a" id="A">
      <img style="color: red" src="http://via.placeholder.com/350x200">
    </div>
    <div class="box b" id="B">
      <img src="http://via.placeholder.com/170x100">
    </div>
    <div class="box c" id="C">
      <img src="http://via.placeholder.com/170x100">
    </div>
    <div class="box d" id="D">
      <img src="http://via.placeholder.com/170x100">
    </div>
    <div class="box e" id="E">
      <img src="http://via.placeholder.com/170x100">
    </div>
    <div class="box f" id="F">
      <img src="http://via.placeholder.com/170x100">
    </div>
  </div>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div class="grid-G-and-H">
  <div id="H_grid">
    <a href="changed-link.html"><img style="margin: auto; width: 23px; height: 27px; left: 20px; position: absolute; top: 0pt; bottom: 0pt;" src="http://via.placeholder.com/23x27"></a>
  </div>
</div>
&#13;
&#13;
&#13;