DEV Community

Cover image for How to Create a Pricing Table of Equal Height
Pinky Lalwani
Pinky Lalwani

Posted on • Edited on

How to Create a Pricing Table of Equal Height

Hi👋
In this post we will see how we can create a Pricing Table of equal height using Flexbox.

Create a div with the class of container

 <div class="container">
Enter fullscreen mode Exit fullscreen mode

We will now create 3 div with the same class pricing-grid inside the container

<div class="pricing-grid">
      <ul>
        <li class="header">Basic</li>
        <li>10Gb Storage</li>
        <li>10 Emails</li>
        <li>10 Domains</li>
        <li>Endless Support</li>
      </ul>
      <p class="price">$ 10</p>
      <p class="month">per month</p>
      <button>Sign Up</button>
    </div>
     <div class="pricing-grid">
      <ul>
        <li class="header">Pro</li>
        <li>10Gb Storage</li>
        <li>10 Emails</li>
        <li>10 Domains</li>
        <li>Endless Support</li>
        <li>Free Hosting</li>
      </ul>
      <p class="price">$ 10</p>
      <p class="month">per month</p>
      <button>Sign Up</button>
    </div>
     <div class="pricing-grid">
      <ul>
        <li class="header">Premium</li>
        <li>10Gb Storage</li>
        <li>10 Emails</li>
        <li>10 Domains</li>
        <li>Endless Support</li>
      </ul>
      <p class="price">$ 10</p>
      <p class="month">per month</p>
      <button>Sign Up</button>
    </div>
Enter fullscreen mode Exit fullscreen mode

CSS

.container{
  max-width:1024px;
  margin:0 auto;
  display:flex;
}
li{
  list-style-type:none;
  padding:30px;
  border-bottom:1px solid rgba(0, 0, 0, 0.3);
}
li:last-child{
  border-bottom:0;
}
li.header{
  border-bottom:0;
  background-color:black;
  color:#fff;
  padding:20px;
}
ul{
  margin:0;
  padding:0;
}
button{
  padding:12px 20px;
  border:none;
  background-color:#000;
  color:#fff;
  align-items:flex-end;
}
Enter fullscreen mode Exit fullscreen mode

So far we have created the basic structure of Pricing Table 😲

Alt Text

This will provide the Proper Spacing and Background color

.pricing-grid{
  flex-grow:1;
  background-color:rgba(0, 0, 0, 0.1);
  margin:20px;
  text-align:center;
  border-radius:4px;
}
Enter fullscreen mode Exit fullscreen mode

Expectation 😀

Alt Text

Reality 🤷‍♀️

Alt Text

This can be achieve by using Nested Flexbox

.pricing-grid{
  display:flex;
  flex-wrap:wrap;
}
.pricing-grid > *{
  flex:1 1 100%;
}
Enter fullscreen mode Exit fullscreen mode

At last align items to the Center

.container{
  align-items:center;
}
Enter fullscreen mode Exit fullscreen mode

I hope this tutorial helped you. 🎉

Top comments (0)