0

Ok, so I have the following layout:

<div class="double_column_left">
    //Left responsive content
</div>
<div class="double_column_right">
    //Right responsive content
</div>

<div class="double_column_left">
    //More left responsive content
</div>
<div class="double_column_right">
    //More right responsive content
</div>

What I need is for the height of each set of columns (each left and right next to each other) to be the same value. So if the left is taller than the right, it would set the right column to the height of the left in Javascript, and vice versa.

This seems like something easily done in Javascript/jQuery, somehow looping through the page and matching each set of div's based on the order it comes across them each time the page is resized; but I've never really done anything like this before and can't think of how to do it.

Any ideas?

user3420034
  • 1,275
  • 2
  • 20
  • 43
  • @3rror404 Thanks for linking to that, although that is more CSS based rather than Javascript as I'm trying to work with. – user3420034 Mar 14 '14 at 13:54
  • look at the answers with 4 up-votes if non of the below are useful – Turnip Mar 14 '14 at 14:04
  • @3rror404 I've ended up going with the flexbox solution on that other post, as it happened to solve a few other issues I was having as well as this issue. – user3420034 Mar 14 '14 at 14:16

4 Answers4

0

Try this

$('.double_column_right').height(function () {
    return $(this).prev().height();
});
Anton
  • 31,487
  • 5
  • 43
  • 54
0

Try this working solution:

Retrieve the height of one div '.double_column_right' and apply it to another div ('.double_column_left')'s min-height. Use the following JQuery code:

var divHeight = $('.double_column_right').height();

$('.double_column_right').css('min-height', divHeight+'px');
Aniruddha Pondhe
  • 1,710
  • 3
  • 15
  • 28
0

This should work:

function resizeColumns() {
    var $leftColumns = $('.double_column_left');
    $leftColumns.each(function() {
        var $leftCol = $(this);
        var $rightCol = $leftCol.next('.double_column_right');
        var height = Math.max($leftCol.height(), $rightCol.height());
        $leftCol.add($rightCol).height(height);
    });
 }

Now you just call this function when you need to resize the columns. Especifically, at page load and when the window size changes:

 $(document).ready(resizeColumns);
 $(window).on('resize', resizeColumns);
Oscar Paz
  • 17,609
  • 3
  • 24
  • 40
0

This will make all column lefts equal all column rights:

JQUERY

var col1 = $(".double_column_left").height(),
    col2 = $(".double_column_right").height();
if (col1 > col2) {$(".double_column_right").height(col1); } else {
    $(".double_column_left").height(col2);
}

http://jsfiddle.net/qExTz/

DreamTeK
  • 29,809
  • 22
  • 103
  • 157