简体   繁体   English

将最后一个div与flexbox的底部对齐

[英]Aligning the last div to the bottom of a flexbox

Scenario : 场景:

  • I'm creating a pricing comparison table and am having difficulties aligning the last div, card-vat-fee , to the bottom of the container. 我正在创建一个定价比较表,并且很难将最后一个div card-vat-fee对准容器的底部。
  • I need to do this because the tiers have longer running lists than one another, causing the last div isn't aligned with the bottom of the container. 我需要执行此操作,因为这些层的运行列表彼此之间的长度更长,导致最后一个div与容器的底部不对齐。
  • How can I get the last div to align to the bottom of the flexbox? 如何获取最后一个div以使其与flexbox的底部对齐?

Tried Case : 尝试案例:

  • Of course, if I set a min-height: 320px; 当然,如果我将min-height: 320px;设置为min-height: 320px; on the card-vat-fee class it will align the div to the bottom, however this isn't a responsive solution and I feel like there is a better approach that uses flex properties. card-vat-fee类上,它将div对齐到底部, 但这不是一种响应式解决方案 ,我觉得有一种使用flex属性的更好的方法。 Moreover, setting the card-vat-fee div to flex-grow, flex: 1 1 auto , produces an unideal solution . 此外,将card-vat-fee div设置为flex-grow, flex: 1 1 auto ,产生不理想的解决方案

Code : 代码:

<div class='pricing__tier'>
 <div class='uni-card-header'>
 </div>
 <div class='uni-card-body'>
   <div class='uni-row-on'>
   </div>
   <div class='uni-row-off'>
   </div>
   <div class='uni-row-on card-vat-fee'>
    <div class='vat-fee-text'>
     Credit card fees and VAT apply. See below for details.
    </div>
   </div>
 </div>
</div>
<style>
    .pricing__tier {
        padding: 0;
        text-align: center;
        display: flex;
        flex-direction: column;
        width: 0%;
        flex: 1;
    }
    .uni-card-body {
        display: flex;
        flex-direction: column;
    }
</style>

Pricing Tier 定价层 定价层


Please Suggest. 请提出建议。
Thanks in advance 提前致谢

Use margin-top:auto on the last div. 在最后一个div上使用margin-top:auto

 .pricing__tier { padding: 0; text-align: center; display: flex; flex-direction: column; width: 25%; flex: 1; height: 200px; /* for demo purposes */ border: 1px solid grey; } .uni-card-body { display: flex; flex-direction: column; flex: 1; } .card-vat-fee { margin-top: auto; /* push to bottom */ background: green; } 
 <div class='pricing__tier'> <div class='uni-card-header'> </div> <div class='uni-card-body'> <div class='uni-row-on'> </div> <div class='uni-row-off'> </div> <div class='uni-row-on card-vat-fee'> <div class='vat-fee-text'> Credit card fees and VAT apply. See below for details. </div> </div> </div> </div> 

1- set the parent div relative position without top & left & right & bottom property 1-设置父div相对位置而没有top&left&right&bottom属性

2- set the last div position absolute with bottom:0;right:0;left:0;height:36px; 2-设置最后一个div位置的绝对位置为bottom:0; right:0; left:0; height:36px;

<style>
  .pricing__tier {
    position:relative;
    padding: 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    width: 0%;
    flex: 1;
  }
  .pricing__tier>.vat-fee-text {
    position:absolute;
    bottom:0;
    right:0;
    left:0;
    height:36px;
  }
 </style>

plaesa try this one : plaesa试试这个:

.uni-card-body {
        display: flex;
        flex-direction: column;
        width: 'for example' 700px;
    }
    .uni-row-on.card-vat-fee{
    align-self: flex-end;
}

Ihope this will help you! 我希望这能帮到您!

 .uni-card-body { display: flex; flex-flow: row wrap; justify-content: center; background: yellow; height: 90vh; } .uni-row-on.card-vat-fee { align-self: flex-end; background: green; } 
 <div class='pricing__tier'> <div class='uni-card-header'> </div> <div class='uni-card-body'> <div class='uni-row-on'> </div> <div class='uni-row-off'> </div> <div class='uni-row-on card-vat-fee'> <div class='vat-fee-text'> Credit card fees and VAT apply. See below for details. </div> </div> </div> </div> 

I've illustrated the thing in the snippet, it'll help. 我已经在代码段中说明了这一点,它将有所帮助。

Note: Content justification, background and height are for demonstration and not necessary. 注意:内容说明,背景和高度仅用于演示,并非必需。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM