1

I'm using multiple line flexbox with flex-direction: column;. And flex container is removed from normal flow (for example with position: absolute;)

.container {
  position: absolute;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 110px;
  background: yellow;
  border: solid 1px black; 
}

.item{
  height: 50px;
  width: 50px;

  border: solid 1px red; 
  margin: 1px; 
  box-sizing: border-box; 
}
<div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>

</div>
https://codepen.io/SakerONE/pen/zJxXXN

How to make container width to grow with the number of columns? Now the width of the container is only one column (50px).

dwjohnston
  • 11,163
  • 32
  • 99
  • 194
Artem Svirskyi
  • 7,305
  • 7
  • 31
  • 43

1 Answers1

0

Do you not just want to use flex-direction:row?. You can limit the number of items per row with the use of flex-basis on each item.

flex-basis:33% on each item will limit to 3 items per row.


Alternatively, use height:auto on .container.

Tom Barden
  • 326
  • 2
  • 13