Align content in a flex container to the bottom

家住魔仙堡 提交于 2020-01-24 20:17:07

问题


Is there a way to have equal height items in flexbox and align all of the content within that container to the bottom?

Currently this is what I have

.quick-menu .menu {
  font-size: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.quick-menu .menu .item {
  margin-top: 30px;
  width: 33.33%;
  align-self: flex-end;
}
.quick-menu .menu .item > img {
  margin: auto;
}
.quick-menu .menu .item > span {
  font-size: 24px;
  font-weight: $bold;
  color: $white;
  text-align: center;
  display: block;
}
<div class="menu">
  <div class="item">
    <img src="/assets/img/menu/sandwiches.png" alt="Frozen Igloo Sandwiches">
    <span>Sandwiches</span>
  </div>
  <div class="item">
    <img src="/assets/img/menu/frozen-custard.png" alt="Frozen Igloo Frozen Custard">
    <span>Frozen Custard</span>
  </div>
  <div class="item">
    <img src="/assets/img/menu/munchies.png" alt="Frozen Igloo Munchies">
    <span>Munchies</span>
  </div>
  <div class="item">
    <span><img src="/assets/img/menu/handcrafted-treats.png" alt="Frozen Igloo Handcrafted Treats">
                    <span>Handcrafted Treats</span>
  </div>
  <div class="item">
    <img src="/assets/img/menu/fountain-sodas.png" alt="Frozen Igloo Fountain Sodas">
    <span>Fountain Sodas</span>
  </div>
  <div class="item">
    <img src="/assets/img/menu/specialty-sundaes.png" alt="Frozen Igloo Specialty Sundaes">
    <span>Specialty Sundaes</span>
  </div>
</div>

回答1:


Yes, but since you don't have a specified height on the container, it defaults to height: auto (content height), and there's no free space to move down.

Once you define a height which allows for extra space, the items can move down with align-items: flex-end on the container, or align-self: flex-end on the items (like you have).



来源:https://stackoverflow.com/questions/40618012/align-content-in-a-flex-container-to-the-bottom

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