4

So I'm struggling to achieve this simple concept with CSS and i've also searched the entire internet but couldn't find anything. I think I'm just not wording it correctly so a visual image of what i'm trying to do is this:

enter image description here

The top box should be positioned on top and the bottom one should be positioned at the bottom. Then the boxes in between them should have equal spacing on top and bottom. This is more like the vertical version of this answer: https://stackoverflow.com/a/6880421/7150896

Community
  • 1
  • 1

2 Answers2

15

You can use Flexbox for this. You just need to set flex-direction: column and justify-content: space-between.

body,
html {
  margin: 0;
  padding: 0;
}
.content {
  display: flex;
  height: 250px;
  border: 1px solid black;
  justify-content: space-between;
  flex-direction: column;
  width: 200px;
}
.box {
  background: #0479D9;
  height: 50px;
}
<div class="content">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176
1

You can also achieve this using grid css layout:

.content {
  display: grid;
  align-content: space-between;
  height: 275px;
  border: 1px solid black;
  width: 200px;
}
.box {
  background: #0479D9;
  height: 75px;
}
<div class="content">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>
Darryl RN
  • 7,432
  • 4
  • 26
  • 46