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
  • 131,796
  • 23
  • 122
  • 195
pjk_ok
  • 639
  • 6
  • 23
  • 69

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
  • 39,721
  • 6
  • 52
  • 88