Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Child DIV Height to Parent DIV Height With Variable Sibling

I have a container <div> with a specified height, and contained within are two more DIVs, on for introductory copy that will vary (entered by the client), and another to list out various features.

I want the features <div> to automatically fill the remaining space in the parent, and then scroll out the overflow.

How do I do that?

CSS:

#article {
    width:940px;
    height:500px
}

#article-content {
    margin: 20px 0;
}

#article-features {
    height:100%;
    overflow-x: auto;
}

jsFiddle

like image 245
Ty Morton Avatar asked Jul 31 '12 12:07

Ty Morton


People also ask

How do you make a parent div the same height as a child?

Using height: auto or using min-height on parent element will work. And for avoiding horizontal scrollbar, which can be caused due to padding or border can be avoided by using box-sizing: border-box on child element or overflow: hidden on parent element.


1 Answers

No way to do it with HTML4 other than relying on javascript to dynamically change the height of the bottom div based upon calculation (parent_height - sibling_height).

You may look at this: CSS HTML - DIV height fill remaining space

With HTML5 you may use Flexbox to use the remaining space. Note that there are some limitations but it can answer your requirements. See http://caniuse.com/#feat=flexbox.

like image 112
unludo Avatar answered Sep 29 '22 19:09

unludo