html - 如何让两个子div的高度彼此相同

标签 html css

我需要使两个 .tinted-container 彼此高度相同(如果可能使用 CSS)但每个都在一个网格列下。

  • 我无法为网格列着色,因为它们使用填充来创建 排水沟,如果有色容器之间没有空白 我给背景着色。
  • 这是一个基于 % 的网格,因此为两者都添加边距 列的宽度超过 100%。

<div class="grid-row">
      <div class="grid-column-half">
        <div class="tinted-container">
          <p>Taller</p>
          <p>column</p>
          <p>on</p>
          <p>left</p>
        </div>
      </div>

      <div class="grid-column-half">
        <div class="tinted-container">
          <p>This container should be the same height as the other one.</p>
        </div>
      </div>
    </div>

如何使容器高度相同?

最佳答案

Flexbox 可以做到这一点:

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.grid-row {
  display: flex;
}
.grid-column-half {
  border: 1px solid grey;
  width: 50%;
  padding: 10px
}
.tinted-container {
  height: 100%;
  background: pink;
}
<div class="grid-row">
  <div class="grid-column-half">
    <div class="tinted-container">
      <p>Taller</p>
      <p>column</p>
      <p>on</p>
      <p>left</p>
    </div>
  </div>

  <div class="grid-column-half">
    <div class="tinted-container">
      <p>This container should be the same height as the other one.</p>
    </div>
  </div>
</div>

关于html - 如何让两个子div的高度彼此相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39391314/

相关文章:

javascript - 如何从 Instagram 应用内浏览器页面链接打开默认浏览器?

html - 表示 UI 小部件的语义 HTML 元素

html - 如何确定 HTML 中文本的高度和宽度?

在写入变量的 div 图像之前,Javascript/jquery 确认预图像加载

javascript - 如何为 html 输入字段分派(dispatch) "invalid"事件

html - 有没有办法改变 Bootstrap 导航栏的高度?

php - 嵌入式 PHP 防止滚动

javascript - 对重复的 HTML 使用相同的 JavaScript

html - 为文章文本区域设置特定宽度

html - 在媒体查询中重置 CSS