Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS inline-block uneven spacing

Tags:

html

css

layout

So I have two columns of cards and each card has the inline-block property. Each is of variable height so there is uneven white space in between each card like so:

inline-block

Short of having two separate columns, how can I get spacing between each card even?

I'm aiming for this layout:

enter image description here

like image 393
najm Avatar asked Jan 21 '26 08:01

najm


1 Answers

Either use column layout, like so:

.cards {
  columns: 300px 2;
}

.cards div {
  display: inline-block;
}

Or use a flex layout:

.cards {
  display: flex;
  flex-direction: row; /* or column if you want them displayed vertically */
}
.cards div {
  flex: 1 1 auto;
}

Or if you just want them displayed at the top always:

.cards div {
   display: inline-block;
   vertical-align: top;
}
like image 90
Josh Burgess Avatar answered Jan 24 '26 10:01

Josh Burgess