Reputation: 3325
I have a div with an image positioned absolutely. But I want to have the height be dynamic, so that it shows the image. Right now, the div ignores the image and will collapse to the content of the text. How can I get the div to show the whole image?
<div style="position:relative; height:auto">
<img style="position:absolute; top:100px; left:100px;"/>
</div>
Upvotes: 0
Views: 1533
Reputation: 7139
Elements that are absolutely positioned are removed from the normal flow. That means that all elements will ignore it, as if it didn't exist. To solve your problem, you need to use JavaScript to get the height of the image and adjust the div's height accordingly.
Upvotes: 1