简体   繁体   English

当 flex-direction 设置为 column 时,如何使用 flexbox 将元素与 div 的底部对齐

[英]How to align an element to the bottom of the div with flexbox when flex-direction is set to column

I know this question has been asked several times, but for some reason my isn't working.我知道这个问题已经被问过好几次了,但由于某种原因我没有工作。 Can you guys please help me?I'm just trying to align all the buttons with all the cards because the tiles could have different lengths one, two or three lines, but I don't know why it's not working.你们能帮我吗?我只是想将所有按钮与所有卡片对齐,因为瓷砖可能有不同的长度,一、二或三行,但我不知道为什么它不起作用。 Thanks!谢谢!

 .cards { max-width: 1200px; display: flex; } .card { flex: 1; margin-right: 30px; } .content { display: flex; flex-direction: column; justify-content: space-between; } .pic { min-height: 20vh; background: blue; }
 <div class="cards"> <div class="card red"> <div class="pic"> </div> <div class="content"> <h1>Lorem ipsum dolor sit ait.Lorem ipsum dolor sit ait </h1> <button>click here</button> </div> </div> <div class="card blue"> <div class="pic"> </div> <div class="content"> <h1>Lorem ipsum dolor sit ait. </h1> <button>click here</button> </div> </div> </div>
This is what I want to look like. 这就是我想要的样子。 两张牌

For use the justify-content: space-between;使用justify-content: space-between; property, a height or width must be defined.属性,必须定义heightwidth

For flex-direction:column is must be defined height对于flex-direction:column必须定义height

 .cards { max-width: 1200px; display: flex; } .card { flex: 1; margin-right: 30px; } .content { display: flex; flex-direction: column; justify-content: space-between; height:200px; } .pic { min-height: 20vh; background: blue; }
 <div class="cards"> <div class="card red"> <div class="pic"> </div> <div class="content"> <h1>Lorem ipsum dolor sit ait.Lorem ipsum dolor sit ait </h1> <button>click here</button> </div> </div> <div class="card blue"> <div class="pic"> </div> <div class="content"> <h1>Lorem ipsum dolor sit ait. </h1> <button>click here</button> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flexbox似乎不遵循flex-direction:标头元素的列 - Flexbox appears to not be honoring flex-direction: column for a header element 以 flex-direction: column 包裹时,Flexbox 滚动会中断 - Flexbox scroll breaks when wrapped in flex-direction: column flexbox 内的弹性方向“行”和弹性方向“列” - flex direction "row" inside a flexbox with flex-direction "column" Flexbox:当flex-direction:列,flex-wrap:wrap时,宽度计算错误 - Flexbox: wrong width calculation when flex-direction: column, flex-wrap: wrap Flexbox 和 Flex-Direction 的替代品 - Alternatives to Flexbox and Flex-Direction FlexBox:同一列上有 2 个元素,而 flex-direction 列 - FlexBox: 2 Elements on the same column while flex-direction column Internet Explorer不会使用flex-direction:列扩展Flexbox - Internet Explorer doesn't expand a flexbox with flex-direction: column flexbox 中的响应图像 - 带有 flex-direction:column 的行为不符合预期 - Responsive image in flexbox - with flex-direction:column not behaving as expected Flexbox(flex-direction:column):当一个孩子具有固定宽度时,包裹的孩子未正确定位 - Flexbox (flex-direction: column): wrapped child not positioned correctly when one child has fixed width flexbox flex-direction:带有textarea的列无法在Firefox中正常工作 - flexbox flex-direction:column with textarea not working as expected in Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM