Floats, Lube and Balloons

You can only float block level elements.

  1. ul
    1. li
    2. li
    3. li
    4. li

Floating an element shrinkwraps it around its contents. They float up like balloons until they hit the ceiling of the block above them.

  1. ul
    1. li
    2. li
    3. li
    4. li

Floating the containing or parent block shrinkwraps it around its contents or child elements.

Whether those children are floated...

  1. ul
    1. li
    2. li
    3. li
    4. li

...or static.

  1. ul
    1. li
    2. li
    3. li
    4. li

Swap Shop

Floats will always go as far to the top (left or right) as they can..

Resize this window and watch the span.

Use floats to position elements in corners.

  1. div
    1. img
    2. h3
    3. p

Clear

Use clears and widths on blocks to pen floats so they don't get away from you.

  1. p {width: 100%;}
    1. li
    2. li
    3. li clear:left
    4. li
    5. li
    6. li clear:left width:100%
    7. li
    8. li
    9. li

But only clear what you need or you can get gaps:

  1. body
    1. div dash
      1. h3
      2. p
      3. p
    2. div main
      1. #main h3 clear:left

Resources

← Back