I want my container div to get the height of max of its children's height. without knowing what height the child div
s are going to have. I was trying out on JSFiddle. The container div
is on red. which is not showing up. Why?
The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.
$(divToResize). css('height',$(container). innerHeight()); $(divToResize) is the selector for the DIV you wish to match the height of it's container and $(container) is logically the container whose height you want to get.
Method 2: We can make the display attribute of the child container to table-row and display attribute of parent container to table, that will take all the height available from the parent div element. To cover all the width, we can make the width of parent div to 100%.
Add the following property:
.c{ ... overflow: hidden; }
This will force the container to respect the height of all elements within it, regardless of floating elements.
http://jsfiddle.net/gtdfY/3/
Recently, I was working on a project that required this trick, but needed to allow overflow to show, so instead, you can use a pseudo-element to clear your floats, effectively achieving the same effect while allowing overflow on all elements.
.c:after{ clear: both; content: ""; display: block; }
http://jsfiddle.net/gtdfY/368/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With