I've got a scenario where I want to dynamically change the number of lines of text that
are visible, while it wraps around a float. The problem is that, once I make the overflow
property of an adjacent block "hidden", the float is excluded from the block (i.e., the block
decreases its width so that the float is no longer inside the block - see example 2).
Hence, the text does not wrap around it but instead just stays to the left (or right) of the float,
and not under/over it as well.
I'm trying to find a way to make this work no matter how many lines are to be shown.
I can make it work if the height of the text will always be larger than the height of the float
(example 3), or if the height will always be smaller than the float (example 2 or equivalent),
but I don't have a solution that can handle both.
1) This is what I start with:
<div>
<div style="float:right;">The Float</div>
<div>aaaa bbbb cccc dddd ...</div>
</div>
Testoverflow:visible height:autooverflow:visible height:auto
2) Now I want to clip the text to 8 lines (10em).
Here's the problem - the width is decreased to exclude the float.
(It's the overflow parameter that does it; it does the same thing if height is auto.)
As far as I understand, this shouldn't happen.
Yes, it
should happen - thanks to Manuel Razzari for this reference. Testoverflow:visible height:autooverflow:hidden height:10em
3) To initially get around this in Firefox, I can clip the content from the outer div instead.
But this won't always do, as shown in the next example.
This will work in IE if I set the height for the outer div instead of the inner, but this
won't always do either, as shown in example 5. Testoverflow:hidden height:autooverflow:visible height:10em
4) But now if I clip the text to a height less than the float,
say 4 lines (5em), it looks like this (doesn't work in IE). Testoverflow:hidden height:autooverflow:visible height:5em
5) If I reduce the height of the outer div instead, the float gets clipped. Testoverflow:hidden height:5emoverflow:visible height:auto
---- Some additional text that shouldn't be hidden
---- 1111 2222 3333 4444 5555 6666 7777 8888 9999
6) A (somewhat convoluted) solution, with small height. I used a hidden float in the blue box,
an absolutely positioned "floating" box in the red box, and another hidden float in the red box
to preserve the height. So, essentially, 3 copies of the floating block. The additional text
gets hidden by the float though. Testoverflow:visible height:autooverflow:hidden height:5em
7) And with larger height. (N/A for IE) Testoverflow:visible height:autooverflow:hidden height:10em
8) And with an even larger height. But now there is blank space at the end. (N/A for IE) Testoverflow:visible height:autooverflow:hidden height:15em