如何将底部的按钮与 Bootstrap 4 对齐? [复制]
Posted
技术标签:
【中文标题】如何将底部的按钮与 Bootstrap 4 对齐? [复制]【英文标题】:How to align the button at the bottom with Bootstrap 4? [duplicate] 【发布时间】:2018-07-23 06:20:16 【问题描述】:我使用的是 Bootstrap 版本4.0.0
这是一个例子:: https://getbootstrap.com/docs/4.0/examples/pricing/
如何使按钮始终与底部对齐?
这里是 jsfiddle:https://jsfiddle.net/34shLh1m/
代码html:
<div class="card-deck mb-3 text-center">
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Free</h4>
</div>
<div class="card-body">
<h1 class="card-title pricing-card-title">$0 <small class="text-muted">/ mo</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>10 users included</li>
<li>2 GB of storage</li>
<li>Email support</li>
<li>Help center access</li>
<li>Help center access</li>
</ul>
<button type="button" class="btn btn-lg btn-block btn-outline-primary">Sign up for free</button>
</div>
</div>
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Pro</h4>
</div>
<div class="card-body">
<h1 class="card-title pricing-card-title">$15 <small class="text-muted">/ mo</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>20 users included</li>
<li>10 GB of storage</li>
<li>Priority email support</li>
<li>Help center access</li>
</ul>
<button type="button" class="btn btn-lg btn-block btn-primary">Get started</button>
</div>
</div>
</div>
照片:
我想做这样的事情:
【问题讨论】:
【参考方案1】:将d-flex flex-column
类应用到卡片主体(它们将卡片主体变成一个弹性列)并将mt-auto
类(margin-top:auto)应用到按钮。 mt-auto
将按钮推到底部。
这是一个工作代码sn-p(点击下面的“运行代码sn-p”按钮并展开到整页):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card-deck mb-3 text-center">
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Free</h4>
</div>
<div class="card-body d-flex flex-column">
<h1 class="card-title pricing-card-title">$0 <small class="text-muted">/ mo</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>10 users included</li>
<li>2 GB of storage</li>
<li>Email support</li>
<li>Help center access</li>
<li>Help center access</li>
<li>Help center access</li>
<li>Help center access</li>
</ul>
<button type="button" class="btn btn-lg btn-block btn-outline-primary mt-auto">Sign up for free</button>
</div>
</div>
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Pro</h4>
</div>
<div class="card-body d-flex flex-column">
<h1 class="card-title pricing-card-title">$15 <small class="text-muted">/ mo</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>20 users included</li>
<li>10 GB of storage</li>
<li>Priority email support</li>
<li>Help center access</li>
</ul>
<button type="button" class="btn btn-lg btn-block btn-primary mt-auto">Get started</button>
</div>
</div>
</div>
【讨论】:
如何在没有卡片布局的情况下做同样的事情?你能帮帮我吗?以上是关于如何将底部的按钮与 Bootstrap 4 对齐? [复制]的主要内容,如果未能解决你的问题,请参考以下文章