I have two divs.
<div class="col-1"><p>Content</p></div>
<div class="col-2"><img src="" alt="" /></div>
With their respected content inside each one.
I am trying to set the height of col-2 to be exactly as that of col-1.
I tried this using jQuery:
$(document).ready(function() {
var divHeight = $('.col1').height();
$('.col2').css('min-height', divHeight+'px');
});
The problem is that col-1 does not have a height set on it. It has a dynamic height which grows when its content grows. Therefore the above code does not work for it.
Is there any way I can set the min height of col-2 to be equal to the dynamic height of col 1 using jQuery?
this works fine for me, its just that your class names are wrong, the class-names should be .col-1
and .col-2
:
$(document).ready(function() {
var divHeight = $('.col-1').height();
$('.col-2').css('min-height', divHeight+'px');
});
Here is the Fiddle
EDIT- Based on comments:
You can do all this without using jquery
Flexbox (not supported in IE 8 & 9) - if you apply the flex to the parent div, it will make all its children heights equal:
.row{ display: flex;}
table - you can give your div's the table layout
.row {display: table; }
.row div { display: table-cell;}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments