My goal is I want my boxes in the first line are 5 rows and the 6th box will go to the next row? Can you show me how to do it?
.container {
display: flex;
gap: 10px;
flex-wrap: wrap;
padding: 10px;
}
.box {
flex: 1;
height: 50px;
background: yellow;
}
<div class="container">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
<div class="box">7</div>
<div class="box">8</div>
<div class="box">9</div>
<div class="box">10</div>
<div class="box">11</div>
<div class="box">12</div>
</div>
3
Answers
Flexbox is a one-dimensional layout method for arranging items in rows or columns. Items flex (grow or shrink) to fill the available space.
Grid is a two-dimensional layout system that lets you lay content out in rows and columns. I believe Grid is the better choice for your intentions.
Your title and description are contradictive, I’m assuming you want 5 columns, and when 5 columns are placed, the new items wrap onto the next wrap.
Set the
flex-basis
equivalent to the value to 100 / what column the wrap should happen at (100 / 6) = 16.66%):Here is an example to fix the issue you are having.
You could also give the
.container
class amax-width
andmargin: 0 auto
to make this responsive. Or use Bootstrap which uses flex box containers with build is resposive features and a ton more.