flex-direction: row - children of same height

空扰寡人 提交于 2020-01-21 19:17:28

问题


How is it possible to get the .childs to all have the same height. height: 100% is not working an neither is flex-grow: 1. What is the recommended approach for this using flexbox?

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

.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>

回答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>



回答2:


Remove the align-items:center from the parent and add flex properties to the children for their content alignment.

.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>


来源:https://stackoverflow.com/questions/58818829/flex-direction-row-children-of-same-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!