CSS Aligning Last Item to the Bottom of a Container Using Flex Attribute

CSS Aligning Last Item to the Bottom of a Container Using Flex Attribute

by Pritom K Mondal

HTML

<ul>
    
    <li>
    <h3>Header</h3>
    <p class="price"><sup>$</sup>100</p>
    <p class="details">CSS Aligning Last Item</p>
    <a class="button" href=""><p>Buy Now</p></a>
</li>
    
    <li>
    <h3>Header</h3>
    <p class="price"><sup>$</sup>100</p>
    <p class="details">CSS Aligning Last Item CSS Aligning Last Item CSS Aligning Last Item</p>
    <a class="button" href=""><p>Buy Now</p></a>
</li>
    
    <li>
    <h3>Header</h3>
    <p class="price"><sup>$</sup>100</p>
    <p class="details">CSS Aligning Last Item</p>
    <a class="button" href=""><p>Buy Now</p></a>
</li>
    
</ul>

CSS

ul {
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-start;
    margin-left: 0;
    list-style-type: none;
    padding-left: 0;
    margin-top: 20px;
    margin-bottom: 20px;
}
ul li {
    display: flex;
    flex-flow: column nowrap;
    margin-top: auto;
    list-style-type: none;
    background: #eee;
    margin: 10px;
    border: 1px solid #777;
    border-radius: 0 0 8px 8px;
    width: 25%;
}
ul li h3 {
    color: #fff !important;
    background: #37383b;
    text-align: center;
    margin-bottom: 0;
    padding-bottom: 7px;
    margin-top: 0;
}
ul li p.price {
    color: #fff !important;
    background: #20988f;
    text-align: center;
    font-size: 30px !important;
    margin: 0;
}
ul li p.details {
    padding: 10px 20px !important;
    margin-bottom: 10px;
    color: #777;
}
ul li a.button {
    background-color: #f78934;
    text-align: center;
    margin-bottom: 0;
    color: #fff;
    text-transform: uppercase;
    padding: 13px;
    border-radius: 0 0 4px 4px;
    margin-top: auto;
    text-decoration: none;
}
ul li a.button p {
   margin: 0;
}