BarryBones41
BarryBones41

Reputation: 1481

Maintain 100% height of columns with dynamic content

In a two column layout, where one column is static and the other has generated content, how can both be maintained to be 100% the height of the wrapper?

https://jsfiddle.net/t1h4vngv/1/

HTML

<div class="wrapper">
  <div class="col left">
    Static stuff
  </div>
  <div class="col right">
    Dynamic Stuff
  </div>
</div>

CSS

html,
body,
.wrapper,
.col {
  height: 100%;
  margin: 0;
  padding: 0;
}

.col {
  float: left;
}

.left {
  background: lightblue;
}

.right {
  background: lightgreen;
}

.thing {
  width: 200px;
  height: 100px;
  background: beige;
  border: 2px solid grey;
}

JS

var el = '<div class="thing">Hi</div>'
var $right = $('.right')
for (var i = 0; i < 20; i++) {
  var $el = $(el);
  $right.append($el)
}

Upvotes: 1

Views: 32

Answers (2)

Paulie_D
Paulie_D

Reputation: 115288

Flexbox can do that:

var el = '<div class="thing">Hi</div>'
var $right = $('.right')
for (var i = 0; i < 10; i++) {
  var $el = $(el);
  $right.append($el)
}
html,
body,
.wrapper,
.col {
  min-height: 100%; /* note min-height */
  margin: 0;
  padding: 0;
  display: flex;
}

.col {
  display: flex;
  flex-direction: column;
}

.left {
  background: lightblue;
}

.right {
  background: lightgreen;
}
.thing{
  width:200px;
  height:100px;
  background:beige;
  border:2px solid grey;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="col left">
    Static stuff
  </div>
  <div class="col right">
    Dynamic Stuff
  </div>
</div>

Upvotes: 2

R. Foubert
R. Foubert

Reputation: 653

The problem here comes from the float. In fact you want to set the same height to two floated elements. Have a look on that ticket HTML/CSS: Making two floating divs the same height

Try to add some content in the right column, you'll see that it works. Hope it helps ;)

Upvotes: 0

Related Questions