grid-auto-columns在Firefox中无法完全正常运行 [英] grid-auto-columns does not completely work in Firefox

查看:93
本文介绍了grid-auto-columns在Firefox中无法完全正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么DIV 3与DIV 1 + DIV 2的大小不同。



这是您的代码火狐浏览器。有问题代码无效/无法识别。





它在Firefox中也会失败:





grid-auto-columns 属性可以根据



因此,最终看来,从 grid-auto-columns grid-template-columns 的简单切换是所有您需要的。


I don't understand why DIV 3 is not the same size as DIV 1 + DIV 2.
https://codepen.io/anon/pen/vaVqPW

.grid {
  display: grid;
  grid-auto-columns: 1fr 1fr; /* I also tried 50% 50% */
  grid-gap: 20px;
}

Firefox 61 should support css grid according to caniuse https://caniuse.com/#feat=css-grid

* {
  box-sizing: border-box;
}

.grid {
  display: grid;
  grid-auto-columns: 1fr 1fr;
  grid-gap: 20px;
}

.content {
  grid-column: 1;
  background: red;
}

.sidebar {
  grid-column: 2;
  background: blue;
}

.grid>* {
  /*border: 1px dashed red; */
  /* demo only */
}

.box {
  width: 50%;
  height: 75px;
  background-color: black;
  color: #fff;
  padding: 20px;
  position: relative;
  float: left;
}

.box100 {
  width: 100%;
  height: 75px;
  color: #fff;
  padding: 20px;
}

.box.arrow-left:after {
  content: " ";
  position: absolute;
  left: -15px;
  margin-top: -15px;
  top: 50%;
  border-top: 15px solid transparent;
  border-right: 15px solid black;
  border-left: none;
  border-bottom: 15px solid transparent;
}

<div class="grid">

  <div class="content">

    <div class="box" style="background:gray">
      DIV 1 (50% of column 1)
    </div>

    <div class="box arrow-left">
      DIV 2 (50% of column 1)
    </div>

  </div>

  <div class="sidebar">
    <div class="box100">DIV 3 (100% of column 2)</div>
  </div>

</div>



<div>

  <div class="content" style="background:tomato">
    <p>content 4 (100% of column 1 + GAP + 100% of column 2 )</p>
  </div>

</div>

解决方案

Firefox does indeed support CSS Grid (see caniuse.com).

The problem is that Firefox does not appear to support multiple values in grid-auto-columns.

This is your code in Chrome. No problems.

This is your code in Firefox. There's a problem. The code is invalid / not recognized.

It fails in Firefox here, too:

The grid-auto-columns property can take multiple values, per the spec definition. However, Firefox appears to lack support for this set-up. It only accepts a single value.

Your correction to the problem, as stated in your answer and copied below, is simply to switch from implicit columns (grid-auto-columns) to explicit columns (grid-template-columns).

grid: auto-flow dense / 1fr 1fr;

The grid property is a shorthand property that allows you to set all explicit and implicit rules in a single declaration. Your rule above breaks down to this:

So in the end, it appears that a simple switch from grid-auto-columns to grid-template-columns was all you needed.

这篇关于grid-auto-columns在Firefox中无法完全正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆