I have a div which wraps a number of images that are generated dynamically. I don't know how high the list of images is. My problem is the div that contains the dynamically generated images doesn't behave like it is housing any content - I want it to extend to the height of the list of images. Each image is itself wrapped in a div.
This is the wrapper div:
.block { padding:10px; margin-top:10px; height:auto; background-color:#f9f9f9; }
This is the markup dynamically generated for (one of) the images:
<div class="block"> <div style="float: left; padding: 2px 2px 2px 2px;"><IMG SRC="45.jpg" BORDER="0"/></div> .....
How do I get the block
div to extend down with the images?
Thanks
Insert a div with {height:100%; overflow-y:auto} into the vertical filler to if the containers height shouldn't expand beyond its preset height. Behold the power of display:table!
If you've faced the situation when you need to wrap words in a <div>, you can use the white-space property with the "pre-wrap" value to preserve whitespace by the browser and wrap the text when necessary and on line breaks.
You set that div with a height that matches the div on the left, then add a child div that is scrollable and expands to 100%. See this fiddle. You can try to fine tune the effect you want to achieve by replacing height by either max-height or min-height . Hope it helps.
The problem you're observing happens when you float an element, which takes it out of the normal flow of the elements (by normal flow I mean the way the elements would appear with no styling). When you float an element, the other elements still in the normal flow will simply ignore it and do not make room for it, which is why your block
div does not extend the full height of your image.
There are a few different solutions:
1) Add the rule overflow: hidden;
to the block
class:
.block { overflow: hidden; padding:10px; margin-top:10px; height:auto; background-color:#f9f9f9; }
2) Add a element after your image that clears the floating:
<div class="block"> <div style="float: left; padding: 2px 2px 2px 2px;"><IMG SRC="images/login1.png" BORDER="0"/></div> <div style="clear: both;"></div> </div>
Both will work, but I prefer the first solution.
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