2

I want to make my own projects tab created 4 divs and gave them display:flex and align-items:center everything works fine but i want to make for example 12 div and 3 column so first column will be 4 div second 4 and third 4

#projects #projects {
    display: flex;
    align-items: center;
    margin-top:15px;
    justify-content: center;
}
#projects div{
    width:200px;
    height:170px;
    background: red;
    display: inline-block;
    margin:0 auto;
}
<div id="projects">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <!-- I want 8 more divs but when I add it they are all in one column -->
</div>
hisbvdis
  • 1,376
  • 1
  • 8
  • 11
stafilo
  • 83
  • 5

1 Answers1

3

You can control the number of columns by adjusting the width of flex items

Result

#projects {
  display: flex;
  flex-wrap: wrap; /* row wrapping*/
  align-items: center;
  margin-top: 15px;
  justify-content: center;
}

#projects div {
  width: calc((100% - 40px) / 4); /* 4 items in row (with 40px for margins) */
  height: 170px;
  background: red;
  display: inline-block;
  margin: 5px;
  border: 1px solid #fff;
  box-sizing: border-box;
}
<div id="projects">
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
  <div>lorem</div>
</div>
hisbvdis
  • 1,376
  • 1
  • 8
  • 11