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?

4 Answers4

0

Try this

$('.double_column_right').height(function () {
    return $(this).prev().height();
});
Anton
  • 32,245
  • 5
  • 44
  • 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,830
  • 3
  • 17
  • 30
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
  • 18,084
  • 3
  • 27
  • 42
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
  • 32,537
  • 27
  • 112
  • 171