【问题标题】:Equal height columns in Firefox (CSS)Firefox (CSS) 中的等高列
【发布时间】:2016-06-08 14:59:36
【问题描述】:

我有一个关于等高列的问题,我知道这类问题一直在技术上被问到(根据我从我的研究中得到的),但不幸的是我已经达到了一个我不知道的点其他尝试。

我在 Chrome 和 Opera 中有相同高度的列,但不知何故 Firefox 不喜欢我这样做的方式。

我有一个简单的标记

<section id="env">
  <div class="container">
    <div class="content">
      <p>
        Way more content than in all the others because this one has so much to say and doesn't know when to stop...it always does that...
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 2
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 3
      </p>
    </div>
  </div>
</section>

#env div 显示为表格,.container div 显示为表格单元格。

#env {
  display: table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 5px;
}

.container {
  display: table-cell;
  border 25px solid transparent;
  width: 33.33333%;
}

.content {
  background: red;
  display: inline-block;
  vertical-align: top;
  height: 100%;
  width: 100%;
  border-radius: 3px;
}

p {
  padding: 0 20px;
}

我为此创建了一个小提琴来关注这个问题:https://jsfiddle.net/vy3Lzu75/1/

如果您在 Chrome 或 Opera 中打开它,您应该会看到三个同样高的红色列。然而,在 Firefox 中,红色列对应于它们各自的内容,而不是实际的容器。

如果有人能指出我正确的方向,我会非常感激,因为到目前为止我所做的一切(将父级的高度设置为 1px,设置子级的最小高度,不同的显示值......)没有'不要在 FF 中做到这一点。

提前致谢!

【问题讨论】:

  • 您的列的高度已经相等,它是 .container 绘制列/单元格。 .content 只是内容 ;) jsfiddle.net/vy3Lzu75/2
  • 天哪...这实际上很愚蠢 :D 你知道,我实际上需要这样的布局(所以我想)让我的列彼此保持一定的距离(宽度透明边框)。但是我可以增加#env div 的边框间距,不是吗?和我看到的效果基本一样。哎呀...无论如何,非常感谢您的提示。现在我可以让它工作了。但是,您是否会碰巧知道 Chrome 和 Firefox 在这种情况下的内容行为不同的原因?
  • 我现在该怎么做才能将此问题标记为基本已解决(因为我认为我无法将评论标记为解决方案)?
  • 由于某种原因,webkit 引擎接受 100% 高度的表格单元格大小,而样式表中没有真正的参考来计算这些 100%,我相信 Firefox 在这里表现良好。
  • 我会添加一个答案并用 flex 给出提示;)

标签: html css firefox dynamic-columns


【解决方案1】:

单元格在这里绘制列。 border-spacing 可用于在 . 周围设置一些区域。

#env {
  display: table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 30px 5px;
}

.container {
  display: table-cell;
  width: 33.33333%;
  background: red;
  border-radius: 3px;
  vertical-align: top;
}

.content {
}

p {
  padding: 0 20px;
}
<section id="env">
  <div class="container">
    <div class="content">
      <p>
        Way more content than in all the others because this one has so much to say and doesn't know when to stop...it always does that...
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 2
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 3
      </p>
    </div>
  </div>
</section>

https://jsfiddle.net/vy3Lzu75/2/


如果你想让内容填满所有可用的空间,你需要添加弹性框,并且可以使用边距来分隔每个列:

#env {
  display: flex;
  width: 100%;
  border-collapse: separate;
  border-spacing: 5px;
}

.container {
  display: flex;
  flex-flow:column;
  margin:5px 30px;
  width: 33.33333%;
  background: red;

}

.content {
  flex:1;
  background:green;
  border-radius: 10px;
}

p {
  padding: 0 20px;
}
<section id="env">
  <div class="container">
    <div class="content">
      <p>
        Way more content than in all the others because this one has so much to say and doesn't know when to stop...it always does that...
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 2
      </p>
    </div>
  </div>
  <div class="container">
    <div class="content">
      <p>
        Content 3
      </p>
      <p>
        Content 4
      </p>
    </div>
  </div>
</section>

https://jsfiddle.net/vy3Lzu75/7/

【讨论】:

  • 非常感谢您提供的解决方案和 flexbox 示例 :) 老实说,我也想到了这一点。但不知何故,我仍然犹豫要不要使用它,因为那里有那么多 IE 僵尸。
猜你喜欢
  • 2011-01-08
  • 2012-12-22
  • 1970-01-01
  • 1970-01-01
  • 2023-02-22
  • 2016-02-22
  • 1970-01-01
  • 2012-03-06
  • 1970-01-01
相关资源
最近更新 更多