伸缩方向:行-高度相同的子级

时间:2019-11-12 12:31:19

标签: css flexbox

如何使AllowHttpStatus都具有相同的高度。 .child无效,height: 100%也无效。使用flexbox的推荐方法是什么?

flex-grow: 1
.parent {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 800px;
}

.child {
  width: 150px;
  background-color: green;
  border: solid 1px black;
}

2 个答案:

答案 0 :(得分:1)

从父级中删除align-items:center并为子级添加flex属性以使其内容对齐。

.parent {
    display: flex;
    flex-direction: row;
    justify-content: center;
    width: 800px;
}

.child {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  width: 150px;
  background-color: green;
  border: solid 1px black;
}
<div class="parent">
  <div class="child">
    Short Text
  </div>
  <div class="child">
    Long Text: Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla
  </div>
  <div class="child">
    Short Text
  </div>
</div>

答案 1 :(得分:1)

.parent {
    display: flex;
    flex-direction: row;
    width: 800px;
    justify-content: center;
    align-items: stretch;
}

.child {
  width: 150px;
  background-color: green;
  border: solid 1px black;
}
<div class="parent">
  <div class="child">
    Short Text
  </div>
  <div class="child">
    Long Text: Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla
  </div>
  <div class="child">
    Short Text
  </div>
</div>