Bootstrap row with columns of different height
Get top-aligned, diverse height columns in Bootstrap via the flexbox utilities. Encase the columns within a .row
using .align-items-start
to align them at the top. Add on .d-flex
and .flex-column
to the columns to handle varying content heights effectively.
This code provides a uniform top alignment across columns of diverse heights.
Fine-tuning your column alignment
Tailor your vertical alignment with the flexbox align-self
utility. You can use .align-self-end
, .align-self-center
, or .align-self-start
on individual columns to get different alignments. Mix and match to get the layout effect you desire.
The art of going beyond
Struggling with the 12-column framework? Bootstrap's grid system allows for nested columns. Introduce a new .row
inside a .col
to ambitiously create more than 12 columns in a single tier.
Achieving the masonry with Masonry
For a Pinterest-like masonry effect, use the Masonry JS plugin. This helps you arrange items into a slick grid and smoothly handles different heights. Works like a charm with Bootstrap 5.
When flexbox and column wrapping collide
With responsive designs, column wrapping is both a blessing and a curse. To preserve column heights while enabling wrapping, apply flex-wrap: wrap;
to your .row
. Add min-height
on columns for uniform aesthetics on smaller screens.
CSS tips for power users
There are times when you need to transcend Bootstrap's inbuilt tools. Here are some tips:
- Appropriate
display: inline-block
for columns to keep them neatly aligned vertically in a single line. - Implement CSS3 columns, brilliant for creating masonry effects primarily for text-based content without relying on JavaScript.
- Utilize Isotope or Masonry jQuery plugins for dynamic, responsive layouts.
Bootstrap classes for the rescue
Bootstrap caters with a myriad of utility classes to fix divergent column heights:
- Use
.clearfix
to troubleshoot unexpected wrapping or floating issues in your rows. - Apply
display: flex;
andflex-direction: column;
on the column classes directly, avoiding the.display-flex
class for a cleaner and more semantic approach.
Was this article helpful?