img in grid在Firefox上占用的空间比Chrome还多

时间:2017-11-14 00:59:21

标签: html css css-grid

在下面的示例中,Firefox(以及Safari)使用img的原始大小,而不是像Chrome那样使其适合网格。这些浏览器有解决方法吗?



for (let i = 0; i < 6; i++)
{
  $("#first").append(`
    <div class="item">
      <img src="http://via.placeholder.com/350x650" />
    </div>
    `);  
}
&#13;
.flex {
  border: 1px solid black;
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.footer {
  height: 20%;
}
.upper {
  flex: 1;
  overflow: auto;
}

#grid {
  border: 1px solid black;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr;
  height: 100%;
  position: relative;
  max-width: 100%;
  text-align: center;
}

.inner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

.item {
  display: inline-block;
  text-align: center;
  min-height: 0;
  min-width: 0;
}

img {
  max-height: 100%;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<div class="flex">
  <div class='upper'>
    <div id="grid">
      <div id='first' class="inner-grid">
      </div>
      <div>
      test
      </div>
      <div class="inner-grid">
      </div>
    </div>  
  </div>
  <div class="footer">
    footer
  </div>
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案