This page contains common float examples.
With the float property, it is easy to float boxes of content side by side:
The grid of boxes can also be used to display images side by side:
In the previous example, you learned how to float boxes side by side with equal width. However, it is not easy to create floating boxes with equal heights. A quick fix, however, is to set a fixed height, like in the example below:
Using fixed heights with floating boxes is not very flexible. It works only if both boxes always have equal content. On mobile or with dynamic content, this can break the layout. This is where CSS3 Flexbox is useful — it automatically stretches all boxes to match the height of the tallest one.
It is also common to build entire web page layouts using the float
property. In this example, we create a basic layout with a header, a sidebar, a main content area, and a footer using CSS floats.