简体   繁体   中英

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.

try this

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

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

You can change height , to min-height

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM