2

Is there a way of making a div the same height as a sibling just with CSS, or is this only achievable with javascript?

In the example i have two divs in a wrapper div, and I would like the one on the left to be the same size as the one on the right.

Code is below.

#wrapper {width: 50%; height; 200px;}
#box1 {background: red;}
#box2 {background: blue; height: 100px;}
.box {float: left; color: white; width: 50%;}
<div id="wrapper">
  <div class="box" id="box1">Box 1</div>
  <div class="box" id="box2">Box 2</div>
</div>
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
pjk_ok
  • 618
  • 7
  • 35
  • 90

1 Answers1

4

You can use display: flex on the wrapper (this works because align-items property is stretch by default) - see demo below:

#wrapper {display: flex;width: 50%; height; 200px;}
#box1 {background: red;}
#box2 {background: blue; height: 100px;}
.box {float: left; color: white; width: 50%;}
<div id="wrapper">
  <div class="box" id="box1">Box 1</div>
  <div class="box" id="box2">Box 2</div>
</div>
kukkuz
  • 41,512
  • 6
  • 59
  • 95