-1

So I've been working on a website now I have some subscription cards which show the features. Now I wanted the cards to always have the same size so I used display table and table-cell so that the smaller card always matches the height of the other card. But both cards have a button (I use anchor tags for button) and I want these to always be on the bottom of the div. But for some reason I can't get it to work. I do not want to use position absolute so I'm wondering are there any other ways to do it?

As you can see in this image I want the button of 'Free' to be on the same height as the one from 'Pro' enter image description here

HTML

<section class="pricing-row">
                <article class="pricing-card">
                    <h3>Free</h3>
                    <h1 class="pricing-value">$0.00<span class="pricing-length">/mo</span></h1>
                    <ul>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                    </ul>
                    <a href="#">Get started</a>
                </article>
                <article class="pricing-card">
                    <h3>Pro</h3>
                    <h1 class="pricing-value">$4.99<span class="pricing-length">/mo</span></h1>
                    <ul>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                        <li>Feature</li>
                    </ul>
                    <a href="#">Get started</a>
                </article>
            </section>

CSS

.pricing-row {
  display: table;
  width: 100%;
  border-spacing: 50px;
}

.pricing-card {
  position: relative;
  display: table-cell;
  border: 1px solid #515151;
  min-height: 100px;
  border-radius: 10px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  text-align: center;
}

.pricing-card > h3 {
  width: 100%;
  font-size: 1.5rem;
  font-weight: 500;
  background-color: #000;
  color: #fff;
  padding: 15px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.pricing-card > ul {
  list-style: none;
  color: #6c757d;
}

.pricing-card > ul li {
  margin: 5px 0px;
}

.pricing-card > a {
  display: inline-block;
  text-decoration: none;
  color: #ff7700;
  border-radius: 5px;
  border: 1px solid #ff7700;
  width: 97.5%;
  padding: 10px;
  margin: 10px 0px;
}

.pricing-card > a:hover {
  transition: 0.3s;
  color: #fff;
  background-color: #ff7700;
}

.pricing-value {
  color: #4e575f;
  font-size: 2.5rem;
  font-weight: 500;
  margin: 20px 0px;
}

.pricing-length {
  color: #6c757d;
  font-size: 2rem;
}

Thanks in advance

Tom Truyen
  • 318
  • 1
  • 3
  • 15

1 Answers1

3

The best way to achieve this would be to use display: flex; (on the container) and margin-top: auto; (on the <a>).

Also, don't use display: table-*; for anything that isn't a <table>. CSS has display: grid; for this exact reason which works much better.

.pricing-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 50px;
  width: 100%;
}

* {
  box-sizing: border-box;
}

.pricing-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid #515151;
  min-height: 100px;
  border-radius: 10px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  text-align: center;
}

.pricing-card > h3 {
  width: 100%;
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
  background-color: #000;
  color: #fff;
  padding: 15px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.pricing-card > ul {
  list-style: none;
  color: #6c757d;
  padding: 0;
}

.pricing-card > ul li {
  margin: 5px 0px;
  padding: 0;
}

.pricing-card > a {
  display: inline-block;
  text-decoration: none;
  color: #ff7700;
  border-radius: 5px;
  border: 1px solid #ff7700;
  width: 97.5%;
  padding: 10px;
  margin: 10px 0px;
  align-self: center;
  margin-top: auto;
}

.pricing-card > a:hover {
  transition: 0.3s;
  color: #fff;
  background-color: #ff7700;
}

.pricing-value {
  color: #4e575f;
  font-size: 2.5rem;
  font-weight: 500;
  margin: 20px 0px;
}

.pricing-length {
  color: #6c757d;
  font-size: 2rem;
}
<section class="pricing-row">
    <article class="pricing-card">
        <h3>Free</h3>
        <h1 class="pricing-value">$0.00<span class="pricing-length">/mo</span></h1>
        <ul>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
        </ul>
        <a href="#">Get started</a>
    </article>
    <article class="pricing-card">
        <h3>Pro</h3>
        <h1 class="pricing-value">$4.99<span class="pricing-length">/mo</span></h1>
        <ul>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
            <li>Feature</li>
        </ul>
        <a href="#">Get started</a>
    </article>
</section>
Mat Sz
  • 2,524
  • 1
  • 10
  • 23
  • Does exactly what I need. Thank you never thought about using margin-top: auto (never really used it that way to be honest) Thanks – Tom Truyen Feb 01 '20 at 18:51