- I’ve always been confused about using Height because I seem to recall Paul O’ and others staying it doesn’t work like you’d expect it to and is not even honored by all browsers?!
Right, well… the rules are more complicated for height than they are for width. And when content enlarges, “height” (rather than min-height) can cause problems with cutting content off.
Setting height in a % is ignored by browsers unless the thing’s parent already has a set (non-%) height.
I would like to avoid using an HTML table, since I don’t think it is necessary or appropriate.
My best guess at how to do this would be to…
1.) Create two DIVs
2.) Give each a Width
3.) Float them to the Left
Lessee, there are a few things off the top of my head; they all have drawbacks.
While an HTML table may not be appropriate, there is the CSS equivalent: display: table.
I’m not sure if all current browsers who support display: table still need a “table” element, a “row” element and then the “cell” elements, but if they all do (Safari used to need all three for example) then you’d have two wrapping divs rather than one.
Outer-est one would be display: table
inner wrapper would be display: table-row
the two side-by-sides would be display: table-cell
Because they’ll follow the rules like a table, if any one “cell” gets taller, the whole row gets taller. Meaning also the other “cell” div.
IE6 and 7 don’t support display: table in any reasonable way. If you need to support them AND it’s an absolute MUST that these two boxes are definitely exactly always the same height, you can’t use this one.
If the same-height thing is approximate though and you’re kinda loose with the restrictions, you can do this (with plain floats, for all browsers):
Find the longest div. If you know what the most amount of content the longest div will have, set a min-height on that div in em’s. Use ugly background colours to see that your stated min-height is taller than the content.
Both divs can then have that min-height (and IE6 gets “height”). If content in one of them grows, it won’t make the other div grow, but unlike height, it won’t stop the div from growing to accomodate the growth of the content.
(so this works pretty well in previews where the preview text is limited to x-characters or never goes beyond so-many lines or something… tho it does break the illusion if the user has text-enlarge)
Those two techniques are the first I consider.