Float:

The float property, like the position property, has the ability to take specific elements out of the normal flow or the page.

The float property specifies that elements should be placed on the far left or far right of a “parent” or “containing element”. All other material will then “flow” around the “floated” element.

The float property takes the following, self-explanatory keywords as input values;

  • left
  • right
  • none

Example 1

In the following example, the same block of html is presented twice. In the first version, floats are used to place two red blocks on the left side, and one on the right side. A heading and paragraph text then “flow” around them.

In the second block, no floats are used, to present a comparison of what “normal flow” would like.

Float Example

Nostrud anim velit sint minim proident labore ullamco labore occaecat eiusmod occaecat et. Eu cupidatat eu quis dolor cillum laboris dolor culpa ut amet duis cillum. Culpa proident culpa fugiat duis esse ex mollit ea occaecat. Ex consectetur excepteur dolore cillum Lorem sit quis ea proident pariatur pariatur dolore proident. Quis cupidatat Lorem id amet esse nulla consequat aliquip sint ad.


No Float Example

Nostrud anim velit sint minim proident labore ullamco labore occaecat eiusmod occaecat et. Eu cupidatat eu quis dolor cillum laboris dolor culpa ut amet duis cillum. Culpa proident culpa fugiat duis esse ex mollit ea occaecat. Ex consectetur excepteur dolore cillum Lorem sit quis ea proident pariatur pariatur dolore proident. Quis cupidatat Lorem id amet esse nulla consequat aliquip sint ad.

Clear

The ‘clear’ property (clear:) tells floated elements which side, if any, they cannot touch other elements inside the same parent element.

This can be used to create vertical menus, or control the flow of content with a containing element.

Example 2

In the below example, the same code from the above “Example 1” was taken. However, a clear: left; was added to the paragraph element. Notice that this forces it to a new line, below the red squares, whereas, before it started between the two squares.

Clear Float Example

Nostrud anim velit sint minim proident labore ullamco labore occaecat eiusmod occaecat et. Eu cupidatat eu quis dolor cillum laboris dolor culpa ut amet duis cillum. Culpa proident culpa fugiat duis esse ex mollit ea occaecat. Ex consectetur excepteur dolore cillum Lorem sit quis ea proident pariatur pariatur dolore proident. Quis cupidatat Lorem id amet esse nulla consequat aliquip sint ad.

{ TODO: }

  1. Visit the article on float and clear by W3Schools.
  2. Read pages 370-376 of Chapter 15 in Duckett.

Previous section:
Next section: