How to prevent a float:left DIV from wrapping?

How to prevent a float:left DIV from wrapping?

am 31.01.2008 02:13:00 von plenty900

Hi folks,

Another question for you:

If I have multiple DIVs side by side using "float: left", and one
happens
to be very wide, how do I ensure that it doesn't wrap?

I have found that for some reason the width of the text inside
is taking precedence, when I want the text inside to wrap
within the DIV.

However I don't want to set the width of the DIV, because it is
a DIV that must grow and shrink when the window is resized.

Thanks!

Re: How to prevent a float:left DIV from wrapping?

am 31.01.2008 09:46:36 von Ben C

On 2008-01-31, plenty900@yahoo.com wrote:
> Hi folks,
>
> Another question for you:
>
> If I have multiple DIVs side by side using "float: left", and one
> happens
> to be very wide, how do I ensure that it doesn't wrap?
>
> I have found that for some reason the width of the text inside
> is taking precedence

Yes, that's how it works. The text helps itself to as much space as it
needs up to the maximum available, where available means the full
content width of the container, _not_ the space to the right of any
other floats that are already in the way. If it no longer fits in that
gap, it drops down.

[...]
> However I don't want to set the width of the DIV, because it is
> a DIV that must grow and shrink when the window is resized.

There is a trick you can do here with block formatting contexts, which
although not guaranteed by the specification, works in today's browsers.

Try this:



....


Left column


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.