Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter bootstrap - setting column height based on max column height [duplicate]

Tags:

I want to make all the columns to same height in a row. So, all columns in a row should have the same height as any column with max height.

Fiddler: https://jsfiddle.net/ebwwvy6m/11/

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-2 bg-warning">
      This is a col-sm-2
      Some test content
       Some test content
        Some test content
         Some test content
    </div>
    <div class="col-sm-6 bg-success">
      .col-sm-6
    </div>
    <div class="col-sm-4 bg-info">
      .col-sm-4      
      Some test content
      Some test content
    </div>
  </div>
</div>

Issue:

enter image description here

Both column 2 and column 3 should expand to have the same height as column 1.

Any help / suggestion will be greatly appreciated.

like image 297
JGV Avatar asked Nov 07 '16 21:11

JGV


People also ask

How do I make two columns equal height in bootstrap?

You should be using a custom selector for one and two the tables styles should not be applied to [class*='col-'] that have defined widths. This method should ONLY be used if you want equal height AND equal width columns. It is not meant for any other layouts and is NOT responsive.

How do you make all col the same height?

As of 2017, the best (and easiest) way to make equal height columns in a responsive design is using CSS3 flexbox. Now we have columns that are equal in height, and their content fills the full height ot the entire column.

How can I make bootstrap 4 columns all the same height?

3 Answers. Show activity on this post. You just have to use class="row-eq-height" with your class="row" to get equal height columns for previous bootstrap versions.

How do I change the size of a column in bootstrap?

This is done by adding the class “col-SIZE-SIZE_TO_OCCUPPY”. For example, . col-md-4 which means take 4 columns on the medium-sized screens. If we stack multiple column classes on a single element we can define how we want the layout to look like on other screens and change the columns to rows as we want.


2 Answers

.row-eq-height{
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}

Add this class with your row class.

<div class="container-fluid">
  <div class="row-eq-height row">
    <div class="col-sm-2 bg-warning">
      This is a col-sm-2
      Some test content
       Some test content
        Some test content
         Some test content
    </div>
    <div class="col-sm-6 bg-success">
      .col-sm-6
    </div>
    <div class="col-sm-4 bg-info">
      .col-sm-4      
      Some test content
      Some test content
    </div>
  </div>
</div>

https://jsfiddle.net/ebwwvy6m/16/

like image 125
Yuri Ramos Avatar answered Sep 23 '22 14:09

Yuri Ramos


The best way to do this is using display:flex; on the parent row and on the col.

Working Demo.

.example {
  display: flex;
}
.example .exaple-items {
  display: flex;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row example">
    <div class="col-sm-2 bg-warning exaple-items">
      This is a col-sm-2
      Some test content
       Some test content
        Some test content
         Some test content
    </div>
    <div class="col-sm-6 bg-success exaple-items">
      .col-sm-6
    </div>
    <div class="col-sm-4 bg-info exaple-items">
      .col-sm-4      
      Some test content
      Some test content
    </div>
  </div>
</div>

Since flextbox is a new CSS feature check the browser compatibility: caniuse.com

And use the vendor prefix:

.example {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
}

If you want to know more about display:flex; read this: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

P.S. The new bootstrap v4 will have this feature integrated.

like image 27
paolobasso Avatar answered Sep 23 '22 14:09

paolobasso