Opposing floats

How elements on the same horizontal behave

Opposing floats appear at either end of their containing block element:

float: left
float: right

In this example, 18em is the minimum width at which both floats still align horizontally (widths (7em * 2) + margins (1em * 4)). Note that horizontal margins, unlike vertical ones, do not collapse.

width: 18em
width: 7em
margin: 1em
float: right; width: 13em

When the containing element has a width below this, the elements stack horizontally, whilst still obeying their respective float directions.

clear: left; width: 9em;

Whilst, at a width of 9em, the elements align vertically (and float direction is, effectively, irrelevant).

And, at a width of just 5em, with the default overflow value (visible), each element ‘escapes’ the container.


Comments

Leave a comment