Jump to content

Fit parent div to child img?


Recommended Posts

I have a div that contains an img and text. The img is floated left at 40% width. The height of the img and  the amount of text may vary. What I want to do is make sure the parent div is at least high enough to enclose the img. (It may be higher if the text is longer than the img, but that case works fine already.) I've tried various overflow settings, but none seem to accomplish this. Is there a way using css or straight js?

Screen Shot 2020-04-14 at 12.47.25 PM.png

Link to post
Share on other sites

If the parent adjusts to image and text height, then is a float issue applying overflow: hidden; to parent should fix the problem. The other option is to use display: inline-block; instead of float for image and text container.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...