2

Why height 100% for the right floated column can't make it 100% height? Now i'm confused what 100% height really means.

https://jsfiddle.net/7ybLa9fj/

How to make 2 column to have equal height if I'm using float?

.wrap {
  height: 100%;
  overflow: hidden;
  width: 400px;
}

.left {
  float: left;
  width: 50%;
  background: #fafafa;
  text-align: center;
}

.right {
  float: right;
  background: #ccc;
  width: 50%;
  text-align: center;
  height: 100%; //make right has the same with left doesn't work
}
<div class="wrap">
  <div class="left">
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>

  </div>
  <div class="right">right content is not</div>
</div>
Manish Patel
  • 3,648
  • 1
  • 14
  • 22
Jenny Mok
  • 2,744
  • 9
  • 27
  • 58

3 Answers3

1

When using percent for height, also the ascendants need a height, all the way to the html, unless one have a fixed height, i.e. viewport units vh, shown in sample 2

Sample 1, with height: 100% on the html, body

html,
body {
  height: 100%;
}

.wrap {
  height: 100%;
  overflow: hidden;
  width: 400px;
}

.left {
  float: left;
  width: 50%;
  background: #fafafa;
  text-align: center;
}

.right {
  float: right;
  background: white;
  width: 50%;
  text-align: center;
  height: 100%;
}
<div class="wrap">
  <div class="left">
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>

  </div>
  <div class="right">right content is not</div>
</div>

Sample 2, with height: 100vh on the wrap

.wrap {
  height: 100vh;
  overflow: hidden;
  width: 400px;
}

.left {
  float: left;
  width: 50%;
  background: #fafafa;
  text-align: center;
}

.right {
  float: right;
  background: white;
  width: 50%;
  text-align: center;
  height: 100%;
}
<div class="wrap">
  <div class="left">
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>

  </div>
  <div class="right">right content is not</div>
</div>

Updated

Also, a more modern way to do something like that is to use Flexbox instead of float, much more responsive and elegant coding.

.wrap {
  display: flex;
  overflow: hidden;
  width: 400px;
}

.left, .right {
  flex-basis: 50%;
  text-align: center;
  border: 1px dotted gray;
}
<div class="wrap">
  <div class="left">
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>
    <p>
      left content is long
    </p>

  </div>
  <div class="right">right content is not</div>
</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
0

Height 100% will take the height as 100% to its parent element if the element inside the div need that much height.

In Your case right div have only one element which dont need this much big height to render.

IN case you want both left and right container to be of same height kindly provide height in px like below

.left{
height:200px
}
.right{
height:200px
}
amit wadhwani
  • 1,140
  • 1
  • 7
  • 12
0

You can't add 100% to be same height, because the element have floa right is not have childrens like element before. And 100% is mean, the height as 100% height children. So you must set the height with 375px to be same height.

.right {
height:375px;
}

See at Js fiddle here : https://jsfiddle.net/7ybLa9fj/1/

user8455694
  • 260
  • 3
  • 12