简体   繁体   中英

height: 100% not working for parent div with floated inner div

I have 3 floated div inside a parent div. first and last div has some fixed height (eg: 100px and 150px). For the second div, I have set the height to 100%. But the height of the second div is not increasing as the parent's height increases.

HTML

<div class="main">
    <div class="one">1</div>
    <div class="two"></div>
    <div class="three">3</div>
    <br style="clear: both" />
</div>

CSS

body, html {
    height: 100%;
}
.main {
    width: 500px;
}
.one, .two, .three {
    float: left;
    width: 150px;
    border: 1px solid #CCC;
    margin-left: 5px;
}
.one {
    height: 100px;
}
.two {
    height: 100%;
}
.three {
    height: 150px;
}

DEMO

You have to set height to parent element (in this case .main ) too, look

.main {height: 100%}

http://jsfiddle.net/p01trnj6/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