I have a div container #parent
and a div child #child
who's child of the parent div .
The #child
div contain text and he is floated left, the problem is that I want the #parent
div to fit the height of the #child` div what ever the height is with keeping the float property also .
#parent{
background: red;
height: auto;
}
#child{
float:left;
}
<div id='parent'>
<div id='child'>
<p>Some text Some text Some text</p>
</div>
</div>
Here is a Jsfiddle
Add overflow:auto
to the parent:
#parent {
background: red;
height: auto;
overflow:auto;
}
#child {
float:left;
}
jsFiddle example
When you float the child, the parent collapses because it's acting as if the child occupies no space. Adding the overflow rule restores the behavior that you're after.
Method :1
#parent{
background: red;
height: auto;
overflow:auto
}
#child{
float:left;
}
http://jsbin.com/yufezamofo/3/
Method:2
#parent{
background: red;
height: auto;
display:table
}
#child{
float:left;
display:table-cell;
}
http://jsbin.com/yufezamofo/2/
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