-2

I have this html code in: jsfiddle and i want to make the all the cells equals responsive.

This example works fine but....i want all the cells to be equal when resizing the browser.

In this example there are 5 cells which occupies all the contaier (4 logo and 1 text).

The last 2 cells (the second row) are not equals (2 cells occupied the whole row). I want to be the same size as the first row (this means: cell cell empty_space).

Is this possible using flex:1 ?

flex: 1

I hope i make my self clear :)

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
calin24
  • 905
  • 3
  • 21
  • 43
  • Similar question here: https://stackoverflow.com/questions/44154580/equal-width-flex-items-even-after-they-wrap – NiK648 Jul 19 '18 at 09:38
  • Links to jsfiddle must be accompanied by code in the question, please do not ignore the rules of SO – Pete Jul 19 '18 at 10:04

1 Answers1

0

You can use "ghost elements" to do this:

.cardHolder {
    display: flex;
    flex-flow: row wrap;
}

.wrap {
  flex: 1;
  min-width: 200px;
}

.card {
    margin: .5em;
    min-width: 200px;
    height: 112px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all .25s ease;
    animation: populate .5s ease-out normal backwards;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card img {
  max-height: 95px;
}
.card:hover {
    transform: scale(1.05);
    z-index: 1;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.2);
}
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

<div class="cardHolder">
  
  <div class="wrap">
    <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
    </div>
  </div>
  
  <div class="wrap">
    <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
    </div>
  </div>
  
  <div class="wrap">
    <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
    </div>
  </div>
  
  <div class="wrap">
    <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
    </div>
  </div>
  
  <div class="wrap">
    <div class="card">    
      <a href=""> WorkDay </a>
    </div>
  </div>
  
  <div class="wrap"></div>
  <div class="wrap"></div>
  <div class="wrap"></div>
 
</div>

ORIGINAL No need to flex :)

.cardHolder {
}

.card {
    float: left;
    margin: .5em;
    height: 112px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all .25s ease;
    animation: populate .5s ease-out normal backwards;
    display: block;
    align-items: center;
    justify-content: center;
    width: calc(100% * (1/3) - 1em);
}

.card img {
  max-height: 95px;
}
.card:hover {
    transform: scale(1.05);
    z-index: 1;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.2);
}
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

<div class="cardHolder">
  
  <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
  </div>
  
  <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
  </div>
  
  <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
  </div>
  
  <div class="card">    
      <a href=""><img class="img-responsive" src="https://www.bitc.ie/wp-content/uploads/2016/07/workday-200x112.jpg"></a>    
  </div>
  
  <div class="card">
    <div class="int-card">
      <a href=""> WorkDay </a>
    </div>
  </div>
  
</div>
SirPilan
  • 4,649
  • 2
  • 13
  • 26
  • of course not, 3 columns if you resize them and they have to fill the space they have to resize aswell. whens thats not what you expected, tell me: what is the desired behavior? – SirPilan Jul 19 '18 at 12:58
  • @calin24 added another answer using ghost elements. – SirPilan Jul 19 '18 at 13:03
  • the desire behavior is like using flex but the elements from last row to have the same size; using this code in the original fiddle: `.cardHolder:after { content: ''; flex: 1; margin: .5em; }` it does the job partially :) – calin24 Jul 19 '18 at 13:05