0

I know a solution to create equal height columns using display:table like:

.row {
    display: table;
    width: 100%;
}

.col{
    display: table-cell; 
}

but my case is a bit different, since I am using flexbox and row class has display:flex:

.row {
  display: flex;
  display: ms-flex;
  flex-wrap: wrap;
}

and all cols have .large-4 class:

.large-4 {
   width: 25%;
   max-width: 25%;
  flex: 0 0 30%;
}

I can't use flex:1 for .large-4 as well because it varies in different viewport. here is a snippet of html:

<div class="row">
  <div class="large-4">
    <div class="card">
      <img src="https://picsum.photos/200/200" alt="author">
      <div class="card-content">
        <h1 class="card-title">Title</h1>
        <p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
        <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
          distinctio
          optio vel aliquam provident, ipsa reprehenderit in corrupti quia ratione quisquam amet veniam totam
          veritatis.
        </p>
      </div>
    </div>
  </div>
  <div class="large-4">
    <div class="card">
      <img src="https://picsum.photos/200/200" alt="author">
      <div class="card-content">
        <h1 class="card-title">Title</h1>
        <p class="grey-text mgb-0">2012-09-05, by Basir Payenda</p>
        <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.
        </p>
      </div>
    </div>
  </div>
  <div class="large-4">
    <div class="card">
      <img src="https://picsum.photos/200/200" alt="author">
      <div class="card-content">
        <h1 class="card-title">Title</h1>
        <p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
        <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
          distinctio.
        </p>
      </div>
    </div>
  </div>
</div>

code-pen link can be found here! how to I acheive equal height columns using flexbox? or any other better solution. thanks

3
  • Hi, I was answering your carousel question but you deleted it! Commented Mar 7, 2020 at 16:52
  • ohh great @ariel, I thought the community didn't welcome it. I am going to undo it Commented Mar 7, 2020 at 16:58
  • stackoverflow.com/questions/60577870/… Commented Mar 7, 2020 at 17:02

2 Answers 2

1

You need to add display: flex to the .large-4 element:

.large-4 {
   width: 25%;
   max-width: 25%;
   flex: 0 0 30%;
   display: flex;
}

You'll notice when you inspect your elements using the inspector tool, large-4 elements are actually all the same height. It's the content inside that is not. So by making the parent element flex, it will make the children elements fill the space.

Sign up to request clarification or add additional context in comments.

3 Comments

Or just add the d-flex class if they're using Bootstrap 4...
That works as well, but they didn't have bootstrap listed as a tag so I went with the ol' property instead :)
If you set the flex-basis to 30% (Specifies the initial size of the flex item) - no meaning her for "width: 25%" value.
0

You already have equal-height columns, but inside them is a container that is contracting to its content. Expand that container.

.card {
    height: 100%;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.