css - 2个高度相同的DIV容器

标签 css html height

我想在两个不同的 div 上获得相同的高度,这两个 div 位于一个父级 div 中。 在详细解释之前,让我向您展示简单的代码:

<div id="wrapper">
  <div id="box_one">
  ...
  </div>
  <div id="box_two">
  ...
  </div>
</div>
#wrapper{
  width:1170px;
  margin:0 auto;
  text-align:left;
}
#box_one{
  width:860px;
  background-color:#FCFCFC;
}
#box_two {
  float:left;
  width:310px;
  background-color:#FCFCFC;
}

这就是基本代码的样子。现在让我来谈谈问题。第一个 div#box_one 将包含动态内容 - 我不能说会有多少 - #box_two 也是如此。但我仍然希望两个 div 共享相同的高度。 min-height 在这里不是一个有用的解决方案,将 wrapper+body+html 设置为 height: 100% 而这两个 dov 也不是甚至不值得考虑,因为它会破坏其他布局。

那么有什么办法或者我必须找到另一种方法而不是使用两个 div 吗?

最佳答案

Live demo here (click).

您真正需要的只是display: table-cell

.foo {
  display: table-cell;
  width: 49%; /* not exact, just for this example */
  vertical-align: top;
}
<div class="foo">Some stuff in here.</div>
<div class="foo">Other stuff in here.</div>

关于css - 2个高度相同的DIV容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20034580/

相关文章:

css - 为什么这个 div 会有一个不必要的大计算高度?

html - 如果页面上没有文本,PHP/CSS 页脚将不会停留在页面底部

css - 如何在右侧设置宽度适合内容 - 动态内容宽度

android - 减少 flutter 中的 expansionTile 高度

html - Bootstrap 4 order Masonry-like column cards 水平而不是垂直

jquery - 如何在 css3 或 jquery 中将背景图像加载为滚动

javascript - 将一个高度加到另一个高度上

css - 跨浏览器方式隐藏选择显示

css - 为什么我的移动浏览器显示的图片与 iPad 不同?

html - 使用 Bootstrap 在移动/桌面上进行另一个 View /订单的最佳实践