Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any reliable, cross-browser way to distribute the remaining space in parent element between several DIVs?

Tags:

css

Background

I am working on a browser-based UI that needs to fill the entire screen without any scrolling. The basic layout is like this:

layout sketch

What I want to achieve

The title div should has a fixed height (2em) and the rest 4 divs/panels should devide the remaining space of the screen according to percentages I set.

What I've tried

The best solution I've found is " CSS - How to force elements to 100% of remaining/available space of parent element without extending beyond it? ", which involves using a container div with position:absolute. This works across all browsers, but requires some additional DIVs to be created. Also, panel 2 can sometimes be forced to start on the next line due to inaccuracies in percentage widths.

My previous solution was based on CSS3 Flexbox, but the model is flawed as it does not resize child elements that have a percentage height after stretching the container boxes (at least Chrome doesn't). (The newer flex-* attributes are only implemented in Chrome and the standard is still changing.)

I have also tried the calc() function; however, it's not yet implemented in Chrome. Also, it requires hard-coding the height of the title element in two places, which I've been trying to avoid.

Edit:

What am I looking for

Just to be clear, I am not asking for a perfect/pure-CSS solution (as none seems to exist). If anyone can suggest any jQuery plug-in or open-source framework that can do this, it would be good enough for me.

In addition, I don't require any backwards compatibility with browser releases before 2012. (As long as the solution uses technology that is implemented in some browser and is going to be implemented by Firefox and Chrome in the near future, it's good enough for me.)

like image 636
billc.cn Avatar asked Mar 12 '12 20:03

billc.cn


1 Answers

A little something thrown together: http://jsfiddle.net/gDTGn/2/

like image 184
isotrope Avatar answered Nov 09 '22 17:11

isotrope