Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the button at the bottom with Bootstrap 4? [duplicate]

I am using version Bootstrap 4.0.0

Here's an example:: https://getbootstrap.com/docs/4.0/examples/pricing/

How can I make a button always aligned to the bottom?

Here is the jsfiddle: https://jsfiddle.net/34shLh1m/

Code 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>

Photo:

I want to do something like this:

enter image description here

like image 605
Matheus Miranda Avatar asked Feb 12 '18 23:02

Matheus Miranda


People also ask

How do I move the button to the bottom in Bootstrap 4?

Just add the align-self-end class to item to align at the bottom.

How do I align a button at the end of Bootstrap?

Answer: Use the text-right Class You can simply use the class . text-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.

How do I align a button to the center in Bootstrap 4?

How to: Bootstrap button center. Add class . text-center to the parent div to align any item inside to the center.

How do I keep the footer at the bottom of Bootstrap 4?

In order for this element position at the bottom of the page, you have to add fixed-bottom to the class footer .


1 Answers

Apply the classes d-flex flex-column to the card-body (they turn the card body into a flex column) and the class mt-auto (margin-top:auto) to the button. mt-auto pushes the button to the bottom.

Here's a working code snippet (click the "run code snippet" button below and expand to full page):

<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>
like image 120
WebDevBooster Avatar answered Oct 15 '22 05:10

WebDevBooster