slash197
slash197

Reputation: 9034

dynamic 100% height on element with float

This is bugging me for the past hour and can't figure it out. Here's a test case to better understand the scenario http://jsfiddle.net/slash197/RvTe7/1/

CSS

html, body {
    height: 100%;
    margin: 0px; 
    padding: 0px;
}
.header {
    height: 10%;
    background-color: red;
}
.content {
    height: 90%
}
    #side-bar {
        height: 100%;
        width: 30%;
        float: left;
        background-color: blue;
    }
    #content-zone {
        height: 100%;
        width: 70%;
        float: left;
        background-color: yellow;
    }

.clearfix:before, .clearfix:after {
    content: "";
    display: table;
    line-height: 0;
}
.clearfix:after {
    clear: both;
}

HTML

<div class="header">
    <h1>test case</h1>
</div>
<div class="content clearfix">
    <div id="side-bar">menu</div>
    <div id="content-zone">page content <button>add more</button></div>
</div>

I can set the initial height of both my floating elements successfully to be 100%. The problem is new content will be added dynamically and the floated containers do not expand as I would expect.

Any help is appreciated.

Upvotes: 1

Views: 187

Answers (3)

Ivan Chernykh
Ivan Chernykh

Reputation: 42196

If it is enough for you that only the yellow box grows , so you can do it like:

#content-zone {
        min-height: 100%;
        height: auto;
        width: 70%;
        float: left;
        background-color: yellow;
    }

JSFiddle: http://jsfiddle.net/RvTe7/3/

Upvotes: 1

sabof
sabof

Reputation: 8192

You can change height, to min-height

#content-zone {
    min-height: 100%;
    width: 70%;
    float: left;
    background-color: yellow;
}

Upvotes: 1

Falguni Panchal
Falguni Panchal

Reputation: 8981

try this

add below class #content-zone{ overflow-y:Scroll; }

http://jsfiddle.net/RvTe7/2/

Upvotes: 1

Related Questions