Answers for "flexbox 2 items per row"

4

flexbox limit items per row

<style>
  .parent {
    display: flex;
    flex-wrap: wrap;
  }

  .child {
    /* percent per item in row. 
    33% = limit to 3 per row. */
    flex: 1 0 33%; 
    margin: 5px;
    height: 100px;
    background-color: blue;
  }
</style>

<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
</div>
Posted by: Guest on December-31-2020
0

flex 2 columns per row

.item {
  width: 100%
}

.container {
  display: flex;
  flex-wrap: wrap;
}

.container > div {
  flex: 50%; /* or - flex: 0 50% - or - flex-basis: 50% - */
  /*demo*/
  box-shadow: 0 0 0 1px black;
  margin-bottom: 10px;
}
/////////////html
<div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>
Posted by: Guest on August-14-2021

Browse Popular Code Answers by Language