0
votes

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

1
“But the height of the second div is not increasing as the parent's height increases” – the parent’s height does not increase, it stays at 0 pixels – because the child elements are floated; that is one of the basic effects of floating. And even if you fixed that, the 100% won’t work – because the height of the parent depends on the height of its children, and that’s a catch 22. This will only work if you give the parent an explicit height (or use a completely different approach).CBroe

1 Answers

1
votes

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

.main {height: 100%}

http://jsfiddle.net/p01trnj6/3/