2

Is it possible to resize right div to the height of left one using just CSS?
My Example

I've tried a jQuery approach like this:

$(document).ready(function () {
   $("#right").css("height", $("#left").height());
});

This approach isn't working well because I have dynamically loaded content in the left div and jQuery approach sometimes miscalculates the height.

I also tried height:100% on the right div but it didn't work.

Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44
ttkalec
  • 741
  • 1
  • 6
  • 26
  • 1
    You can try to bind a function to handle every time height changes the height on the right div gets resized automatically. The thing about `$(document).ready()` is that it is fired only once when the page is finished loading so when you are adding stuff dynamically it might not be causing the event to be fired. – redDragonzz Oct 23 '12 at 08:48
  • Why not to use tables? Maybe it is not that cooooooool as blocks layout but it solves the problem without any hacks. – VisioN Oct 23 '12 at 08:49
  • I'm aware of that, and that isn't the issue. I thought that maybe I don't need to use JavaScript at all if it can be solved using pure CSS. – ttkalec Oct 23 '12 at 08:50
  • 1
    Possible solution: http://stackoverflow.com/a/8741070/681807 – My Head Hurts Oct 23 '12 at 08:53

2 Answers2

4

For this you can use display:table property for this. Write like this:

#left{
    margin-right: 15px;
    width: 425px;
    background-color:#11DD52;
}

#right{
    width:200px;
    background-color:#4477AA;
}
#left, #right{
  display:table-cell;
}

Check this http://jsfiddle.net/ZZBM5/

sandeep
  • 91,313
  • 23
  • 137
  • 155
0

EDIT: If you love hacky way of doing things, @sandeep created this great workaround.

I ended up using this great jQuery resize plugin. I was hoping there is an easy CSS solution, but the couple of answers in the comments above give me additional browser compatibility issues.
This is what I've done:

$("#left").resize(function () {
    $("#right").css("height", $(this).height());
});
ttkalec
  • 741
  • 1
  • 6
  • 26