Skip to content Skip to sidebar Skip to footer

Div With Min-height And The Child Div Have The Height Of Parent

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%; } #

Solution 1:

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/

Solution 2:

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

Solution 3:

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.

Post a Comment for "Div With Min-height And The Child Div Have The Height Of Parent"