4

Div with min-height and the child div have the height of parent.

Is it possible with only CSS or javascript is needed?

Example:

#main {
    min-height: 300px;
    width: 100%;
}

#menu, #content {
    float: left;
    width: 50%;
}

#menu {
    height: 150px;
    background-color: red;
}

#content {
    height: 100%;
    background-color: green;
}


<div id="main">
            <div id="menu">menu</div>
            <div id="content">content</div>
<div>
Nick
  • 1,417
  • 1
  • 14
  • 21
João Sousa
  • 59
  • 1
  • 7

3 Answers3

4

may be you can give position:absolute to your content div to make it's equal height of it's parent

css:

#main {
    min-height: 300px;
    width: 100%;
    position:relative;
    background-color: yellow;
}

#menu, #content {
    float: left;
    width: 50%;
    overflow:hidden;
}

#menu {
    height: 150px;
    background-color: red;
}
#content {
    height: 100%;
    background-color: green;
    position:absolute;
    top:0;
    right:0;
}

check this http://jsfiddle.net/sandeep/hKttB/

EDIT there are other option also . You can give min-height to your content div also if the content increase the height of the main div also increase.

#content {
    height: 100%;
    min-height:300px;
    background-color: green;
}

check this fiddle http://jsfiddle.net/sandeep/SRJrF/2/

sandeep
  • 91,313
  • 23
  • 137
  • 155
  • Mmh, the solution may work, but what about the content becomes higher? You cut it with `overflow:hidden`. Why then specifying a `min-height` rather than `height`? Thought the requirement for `min-height` implied the content can be higher than 300px and should grow in that case. – DanielB Jun 28 '11 at 09:09
0

I would try this:

In this case I forced same min height for the child div when there is less content. If content exceeds, the automatic overflow.

#content {
    min-height: 300px;
    overflow:auto;
    background-color: green;
}

This is how we have content div in our nested master page. Hope same will work for you.

Thanks

kheya
  • 7,546
  • 20
  • 77
  • 109
0

i think its not possible.

but you can try something like this. jsFiddle

#main {
    width: 100%;
    height:300px;
    min-height:300px;
}

#menu,
#content{
    float: left;
    display:inline;
    width: 50%;
    position:relative;
}

#menu {
    height: 150px;
    background-color: red;
}

#content {
    height: 100%;
    background-color: green;
}

also please read this min-height regarding min-height.

rrapuya
  • 298
  • 2
  • 10