[英]Aligning the last div to the bottom of a flexbox
Scenario : 场景:
card-vat-fee
, to the bottom of the container. card-vat-fee
对准容器的底部。 Tried Case : 尝试案例:
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>
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.