Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Floated Div height issue, no simple solution?

I have an issue with CSS I can't solve.

I've made a little diagram.

Let's say that the pink and green box's height are determined by there content. The pink box could sometimes be the smaller one.

What I am trying to do is have the smaller box fix it's height to the outer containing div, so that it would have the same height as the pink box (or vice-versa).

Anyone have any solutions?

Min-height on the pink and green boxes won't work because they may exceed that height (also no IE6 support).

100% height on the pink and green boxes won't work because the outer div does not have a fixed height.

A table would work, but come on, a table?

I could fake backgrounds and left-right-borders on the pink and green boxes by putting them in the outer div's background. But that seems messy.

At the moment I have a js solution, but there must be a simpler one.

Cheers.

like image 623
MintDeparture Avatar asked Feb 10 '10 13:02

MintDeparture


3 Answers

Apart from Javascript/Jquery or tables, the only thing I can think of is a display: table-cell based solution (explanation here) - but that won't work in IE either, and there isn't much difference to using a table straight away, is there?

I'd say this is one of the rare cases where, due to sucky CSS specifications and/or implementations, there is no way around a table.

Edit: As other answerers have pointed out, there are CSS workarounds ("Faux columns") that will work in most cases. Using "CSS tables" (using display: table properties) I do not deem valid solutions yet, as they are not supported by IE6, a browser that still has a considerable market share.

like image 101
Pekka Avatar answered Sep 30 '22 13:09

Pekka


Use the Faux Columns technique for that. Basically, you’ll have to use a repeating background image on the parent element containing both boxes.

like image 23
Mathias Bynens Avatar answered Sep 30 '22 11:09

Mathias Bynens


This is the same as the same height columns problem, see this blog post for a solution.

like image 27
Lazarus Avatar answered Sep 30 '22 11:09

Lazarus