Home > Software design >  Flexbox make columns equal heights
Flexbox make columns equal heights

Time:10-22

I am trying to get 3 columns in a row and be the same height.

I am using the HTML/CSS below. I can't figure out why the boxes arent the same height.

.container {
  text-align: center;
  display: block;
  width: 100%;
}

.grid {
  width: 100%;
  height: 100%;
}

.row {
  display: flex;
  height: 100%;
  flex-direction: row;
}

.col {
  background: #444;
  padding: 2em;
  flex: 1;
  height: 100%;
  border: 1px solid blue;
}
<div class="container">
  <div class="data">
    <div class="grid">
      <div class="row">
        <div class="col">
          <p>col 1</p>
        </div>
        <div class="col">
          <p>col </br>2</p>
        </div>
        <div class="col">
          <p>col 3</p>
        </div>
      </div>
    </div>
  </div>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

How can I make the boxes all the same height. thanks

CodePudding user response:

Simply, remove the height: 100% from .col.
flex: 1; will do the job.

.row {
  display: flex;
}

.col {
  flex: 1;
  background: #444;
  padding: 2em;
  border: 1px solid blue;
  text-align: center;
}
<div class="container">
  <div class="data">
    <div class="grid">
      <div class="row">
        <div class="col">
          <p>col 1</p>
        </div>
        <div class="col">
          <p>col </br>2</p>
        </div>
        <div class="col">
          <p>col 3</p>
        </div>
      </div>
    </div>
  </div>
</div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related