html - Flexbox 中具有相同高度的双行

标签 html css flexbox

我创建了一个表格,其中第一列使用两行,因此接下来的列将有两行,但高度相同。有些单元格将有 2 行或更多行,而其他则没有。所以,我希望它们具有相同的高度,即第一行高度的一半。

我试过添加 min-width: 50%,但没有成功。

.double-row {
  display: flex;
  border: 2px solid blue;
}

.col {
  border-right: 1px solid grey;
}

.first-col {
  display: flex;
  align-items: center;
  padding: 10px;
}

.other-col {
  display: flex;
  flex-direction: column;
}

.cell {
  padding: 10px;
  border-bottom: 1px solid grey;
}

.cell.upper {
  background: #00FF002F;
}

.cell.down {
  background: #FF00002F;
}
<div class="double-row">
  <div class="col first-col">
    <h1>
      Double Row
    </h1>
  </div>
  <div class="col other-col">
    <div class="cell upper">
      <p>
        Upper Text
      </p>
    </div>
    <div class="cell down">
      <input type="text">
      <p>
        Bottom Text
      </p>
      <p>
        Bottom Text
      </p>
      <p>
        Bottom Text
      </p>
    </div>
  </div>
  <div class="col other-col">
    <div class="cell upper">
    </div>
    <div class="cell down">
      <input type="text">
      <p>
        Bottom Text
      </p>
    </div>
  </div>
</div>

https://codepen.io/Agusbeche/pen/ZNvMPb

最佳答案

你可以直接插入

<p>&nbsp;</p>在另一列中进行快速修复。但这实际上不是一个好的解决方案,您应该这样做:

添加height: 50%;给里面的 children col

.double-row {
  display: flex;
  border: 2px solid blue;
}

.col {
  border-right: 1px solid grey;
}

.first-col {
  display: flex;
  align-items: center;
  padding: 10px;
}

.other-col {
  display: flex;
  flex-direction: column;
}

.cell {
  flex-grow: 0;
  height: 50%;
  max-height: 50%;
  padding: 10px;
  border-bottom: 1px solid grey;
  overflow: hidden;
}

.cell.upper {
  background: #00FF002F;
}

.cell.down {
  background: #FF00002F;
}
<div class="double-row">
  <div class="col first-col">
    <h1>
      Double Row
    </h1>
  </div>
  <div class="col other-col">
    <div class="cell upper">
      <p>
        Upper Text
      </p>
    </div>
    <div class="cell down">
      <input type="text">
      <p>
        Bottom Text<br/>
        Bottom Text<br/>
        Bottom Text<br/>
        Bottom Text<br/>
        Bottom Text<br/>
      </p>
    </div>
  </div>
  <div class="col other-col">
    <div class="cell upper">
    <!-- OR DO THIS: <p>&nbsp;</p> -->
    </div>
    <div class="cell down">
      <input type="text">
      <p>
        Bottom Text
      </p>
    </div>
  </div>
</div>

关于html - Flexbox 中具有相同高度的双行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56263850/

相关文章:

javascript - 联系表格 - 仅在 html 中包含的 Html 和 Javascript (tumblr)

html - 仅使用 html/css float 表格元素

css - 图标按钮在加载前初始渲染时显示文本 - 谷歌字体

html - 响应式图像,如果容器较大,则宽度不会为 100% - 容器为 Flexbox

android - React Native 上的 Right is Left

html - Flexbox 在 Safari 中不工作

html - 如何为响应式网站创建带滚动条的固定背景?

javascript - jQuery icheck 插件在追加后不起作用

html - 良好的 MVC 实践 - 何时使用分部 View

javascript - 通过td类和jquery单元格中的特定值从表中获取行