How can I make a div grow its height when it has floats inside of it? I know that defining a value for the width and setting overflow to hidden works. The problem is that I need a div with the overflow visible. Any ideas?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
New Answer for 202x:
In order for a parent to wrap around children elements which are floated, a new block formatting context needs to be set on the parent. This is easily done with:
or
The latter is a bit newer. Either of these have an advantage over
overflow: auto;because they have the explicit purpose of creating a new block formatting context, whileoverflow: autoworks as a side effect. Interestingly,flow-rootcan be also used alongsideblockorinlinefor better layout control. For example:Read more:
flow-rootas a value fordisplaypropertycontainpropertyOriginal Answer from 2011:
overflow:auto;on the containing div makes everything inside of it (even floated items) visible and the outer div fully wraps around them. See this example: