Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css issue div height when using float

Tags:

css

css-float

I have a div area like this:

<div class="con">
    <div class="container"></div>
    <div class="sidebar"></div>
</div>

And CSS:

.con{
    width:100%;     
}
.con .container{
    width:70%;
    min-height:500px;
    float:left;
    background:#f00;

}
.con .sidebar{
    width:30%;
    min-height:500px;
    float:right;
    background:#ccc;

}

The container and sidebar class heights are dynamic. When one of these class heights increases, class con also has to increase. But my problem is class con height is always 0, I can't seem to give the con class a static height.

like image 952
Wazan Avatar asked Feb 07 '13 04:02

Wazan


People also ask

How do I stop DIVS from resizing?

It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none.

Why does my div have no height?

The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.


1 Answers

Add overflow: auto; to .con:

.con {
    width: 100%; 
    overflow: auto;    
}
like image 116
Taig Avatar answered Sep 30 '22 13:09

Taig