Jay@TastefulTitles.com Posted April 14, 2020 Share Posted April 14, 2020 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? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 14, 2020 Share Posted April 14, 2020 Remove float? What happens? Are you using positioning anywhere? Link to comment Share on other sites More sharing options...
Jay@TastefulTitles.com Posted April 14, 2020 Author Share Posted April 14, 2020 Removing the float sends all the text below the img, which keeps the div from being too short, but is clearly not what I want. No, there is no positioning in this div. Do you have something to suggest? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 14, 2020 Share Posted April 14, 2020 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 comment Share on other sites More sharing options...
Jay@TastefulTitles.com Posted April 14, 2020 Author Share Posted April 14, 2020 Overflow:hidden seems to do the trick. I thought I had tried all the options, but I might have assumed incorrectly that hidden would hide part of the img. Thanks a million! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now