Vertically justify content

22,808

As usual, no matter how long I search, I find the answer only immediately after I ask the question. :D

For those curious, or for my own future reference: Flexbox's justify DOES work, you just need a few more options:

HTML:

<div id="outer-container">
  <div class="inner-element"></div>
  <div class="inner-element"></div>
  <div class="inner-element"></div>
  <div class="inner-element"></div>
  <div class="inner-element"></div>
  <div class="inner-element"></div>
  <div class="inner-element"></div>
</div>

CSS:

#outer-container {
  height: 250px;
  width: 200px;
  background: red;
  display: flex;
  justify-content: space-around;
  flex-direction: column;
}

.inner-element {
  width: 200px;
  height: 10px;
  background: blue;
}

https://css-tricks.com/almanac/properties/j/justify-content/

https://jsfiddle.net/WW3bh/

Share:
22,808
Rockster160
Author by

Rockster160

Updated on July 09, 2022

Comments

  • Rockster160
    Rockster160 almost 2 years

    Hopefully this isn't an unsolved task, but I'm trying to vertically justify an unknown (ish) number of divs inside of a container.

    Each div should be equal distances from each other, and, additionally, the same distance from the edges. (Assuming the last part can be accomplished using ghost elements before and after)

    The divs will each fill the width of the container, and the container is a set height, but the number of elements inside the container is unknown.

    I'm assuming it can be done using Flexbox to some degree, but have been unsuccessful in my attempts thus far.