Reputation: 1630
The parent height is set to auto but does not grow, because the child div has a float to the left. What is happening here, how can I fix it?
HTML
<div class="wrap">
<div class="content">....</div>
</div>
CSS
.wrap{
background: blue;
width:600px;
height: auto;
border: solid 3px;
}
.content{
background: red;
width:200px;
padding: 10px;
height: auto;
float: left;
}
Upvotes: 0
Views: 83
Reputation: 3802
You can either add overflow:auto
to your wrap div
or clear the floats.
Solution 1:
HTML:
<div class="wrap">
<div class="content">....</div>
</div>
CSS:
.wrap{
background: blue;
width:600px;
height: auto;
border: solid 3px;
overflow:auto;
}
SOLUTION 2:
<div class="wrap">
<div class="content">....</div>
<div class="clr"></div>
</div>
CSS:
.clr
{
clear:both;
}
Please refer the below link for better understanding: Clearing floats
Upvotes: 2
Reputation: 3882
You could change the overflow parameter but this impacts the overflow behaviour. Using floats goes together with a clear:all div, it's like tracing a imaginative line under your flatings to start over on a new line.. some kind of line break but for the floats... Add a last sibling div with style clear:both
<div class="wrap">
<div class="content">....</div>
<div style="clear:both"></div>
</div>
Upvotes: 2
Reputation: 1410
Just like Vincent Durpez said, and here you can see the
js fiddle [http://jsfiddle.net/Xksbs/5/]
Upvotes: 1
Reputation: 67217
There's nothing wrong in setting float left to the child, You have to just add overflow:hidden
to the parent div to achieve your need
Upvotes: 1