Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set height of <div> = to height of another <div> through .css

I have two <div> elements. Right now my simplified .css is thus:

#leftdiv {     /*this is the navigation pane*/     min-height: 600px;     max-height: 600px; } #rightdiv {     /*this is the primary pane*/     min-height: 600px;     max-height: 600px;     overflow-y: auto; } 

I've set a hard min- and max-heights for both so they keep the same height, and if content overflows out of the #rightdiv, a scrollbar appears. I'd like this scrollbar to be gone and having the #rightdiv and #leftdiv stretch to fit the contents of the #rightdiv. I want the whole site to stretch height-wise to fit the contents, but if I remove the overflow-y: auto; from my .css and remove the max-heights, the #rightdiv stretches, but the #leftdiv doesn't, yielding some truly ugly design.

I'd like something like the below:

#leftdiv {     min-height: equal to #rightdiv height if #rightdiv is taller, else 600px; } #rightdiv {     min-height: equal to #leftdiv height if #leftdiv is taller, else 600px; } 

How would I go about setting the min-height of both like this?

like image 640
gator Avatar asked Oct 21 '13 00:10

gator


People also ask

How do I make div height equal to another div?

Place both DIVs into a container DIV that's set to 100% of page height and set both interior DIVS to 100%. They will fill up the container DIV and the height of both will be equal.

How dynamically change the height of a div?

The content height of a div can dynamically set or change using height(), innerHeight(), and outerHeight() methods depending upon the user requirement.

How do you inherit height in CSS?

height: 100% will match the height of the element's parent, regardless of the parent's height value. height: inherit will, as the name implies, inherit the value from it's parent. If the parent's value is height: 50% , then the child will also be 50% of the height of it's parent.


1 Answers

If you don't care for IE6 and IE7 users, simply use display: table-cell for your divs:

demo

Note the use of wrapper with display: table.

For IE6/IE7 users - if you have them - you'll probably need to fallback to Javascript.

like image 55
Michał Rybak Avatar answered Sep 21 '22 14:09

Michał Rybak