Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bootstrap column height to 100% row height? [duplicate]

I haven't found a suitable solution to this and it seems so trivial.

I have two columns inside a row:

<div class="row">
  <div class="col-xs-9">
    <div class="left-side">
      <p>sdfsdf</p>
      <p>sdfsdf</p>
      <p>sdfsdf</p>
    </div>
  </div>
  <div class="col-xs-3">
    <div class="something">asdfdf</div>
  </div>
</div>

The row height is set by the larger row, left-side. However, I want the right side's height to be the same.

This seems intuitive, but it doesn't work

.left-side {
    background-color: blue;
}
.something {
    height: 100%;
    background-color: red;
}
.row {
    background-color: green;
}

http://jsfiddle.net/ccorcos/jz8j247x/

like image 726
Chet Avatar asked Aug 08 '14 22:08

Chet


People also ask

How do I make bootstrap columns equal height?

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 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 height of a row in bootstrap?

Note: The height of the row (or any other element) will be relative to the height of its parent. That means if you set 100px height to the parent of the row, and then you will set the height of the row to 50%, the row will be 50px height. The red div below is 100px height and all the child element are relative to it.

How do I make a div the same height in a row?

Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.


2 Answers

You can solve that using display table.

Here is the updated JSFiddle that solves your problem.

CSS

.body {
    display: table;
    background-color: green;
}

.left-side {
    background-color: blue;
    float: none;
    display: table-cell;
    border: 1px solid;
}

.right-side {
    background-color: red;
    float: none;
    display: table-cell;
    border: 1px solid;
}

HTML

<div class="row body">
        <div class="col-xs-9 left-side">
            <p>sdfsdf</p>
            <p>sdfsdf</p>
            <p>sdfsdf</p>
            <p>sdfsdf</p>
            <p>sdfsdf</p>
            <p>sdfsdf</p>
        </div>
        <div class="col-xs-3 right-side">
            asdfdf
        </div>
    </div>
like image 134
Alan Souza Avatar answered Oct 10 '22 04:10

Alan Souza


@Alan's answer will do what you're looking for, but this solution fails when you use the responsive capabilities of Bootstrap. In your case, you're using the xs sizes so you won't notice, but if you used anything else (e.g. col-sm, col-md, etc), you'd understand.

Another approach is to play with margins and padding. See the updated fiddle: http://jsfiddle.net/jz8j247x/1/

.left-side {
  background-color: blue;
  padding-bottom: 1000px;
  margin-bottom: -1000px;
  height: 100%;
}
.something {
  height: 100%;
  background-color: red;
  padding-bottom: 1000px;
  margin-bottom: -1000px;
  height: 100%;
}
.row {
  background-color: green;
  overflow: hidden;
}
like image 40
Esteban Avatar answered Oct 10 '22 03:10

Esteban