将最后一个 div 对齐到 flexbox 的底部
Aligning the last div to the bottom of a flexbox
场景:
- 我正在创建价格比较 table,但很难将最后一个 div、
card-vat-fee
与容器底部对齐。
- 我需要这样做,因为层的 运行 列表比
一个又一个,导致最后一个 div 没有与底部对齐
容器。
- 如何让最后一个 div 对齐到 flexbox 的底部?
试用案例:
- 当然,如果我在
card-vat-fee
class 上设置 min-height: 320px;
它会将 div 对齐到底部,然而这是这是一个响应式解决方案,我觉得有更好的方法可以使用 flex
属性。此外,将 card-vat-fee
div 设置为 flex-grow flex: 1 1 auto
会产生 unideal solution.
代码:
<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>
定价层
请建议。
提前致谢
1-设置parent div相对位置无top & left & right &
底部 属性
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>
请试试这个:
.uni-card-body {
display: flex;
flex-direction: column;
width: 'for example' 700px;
}
.uni-row-on.card-vat-fee{
align-self: flex-end;
}
希望对您有所帮助!
.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>
我已经在代码片段中说明了事情,它会有所帮助。
Note: Content justification, background and height are for demonstration and not necessary.
在最后一个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>
场景:
- 我正在创建价格比较 table,但很难将最后一个 div、
card-vat-fee
与容器底部对齐。 - 我需要这样做,因为层的 运行 列表比 一个又一个,导致最后一个 div 没有与底部对齐 容器。
- 如何让最后一个 div 对齐到 flexbox 的底部?
试用案例:
- 当然,如果我在
card-vat-fee
class 上设置min-height: 320px;
它会将 div 对齐到底部,然而这是这是一个响应式解决方案,我觉得有更好的方法可以使用flex
属性。此外,将card-vat-fee
div 设置为 flex-growflex: 1 1 auto
会产生 unideal solution.
代码:
<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>
定价层
请建议。
提前致谢
1-设置parent div相对位置无top & left & right & 底部 属性
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>
请试试这个:
.uni-card-body {
display: flex;
flex-direction: column;
width: 'for example' 700px;
}
.uni-row-on.card-vat-fee{
align-self: flex-end;
}
希望对您有所帮助!
.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>
我已经在代码片段中说明了事情,它会有所帮助。
Note: Content justification, background and height are for demonstration and not necessary.
在最后一个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>