Use floats, clearing, and multicolumn layouts.
Some layouts need text to wrap around a small box or continue from one column into another. Floats and multicolumn layout handle these reading patterns without positioning every piece of content individually.
A float moves a box to one side of its container and lets surrounding inline content wrap around it.
.fact {
box-sizing: border-box;
float: left;
width: 10rem;
max-width: 100%;
margin: 0 1rem 1rem 0;
padding: 1rem;
background-color: honeydew;
}The fact box moves to the left. The paragraph stays in normal flow, but its first lines use the space beside the float’s margin box. Lines below the float regain the full width. Narrow the article and watch which word first appears below the fact box.
To start a heading below the fact box, put the heading after the paragraphs, inside the same article. Give it a clearing class.
.fact {
box-sizing: border-box;
float: left;
width: 10rem;
max-width: 100%;
margin: 0 1rem 1rem 0;
padding: 1rem;
background-color: honeydew;
}
.next {
clear: both;
}clear: both moves the heading below earlier floats on either side within the same block layout region. Use left or right to clear just one side.
Clearing changes where the following box begins. It does not turn the earlier float back into an ordinary in-flow box.
flow-rootA parent with automatic height can end before the bottom of a tall floated child because that child is out of normal flow. This is especially noticeable when the parent's only child is a float.
.article {
display: flow-root;
padding: 1rem;
border: 1px solid green;
}flow-root creates a separate block layout region, called a block formatting context. The parent grows tall enough to contain its floats, and outside floats cannot push into its content.
The fact box still floats and the article’s text still wraps around it. flow-root contains the float without clipping content that overflows.
Multicolumn layout divides one continuous content stream into columns. For a separate example, use a section with several paragraphs:
.column-text {
column-width: 16rem;
column-gap: 2rem;
column-rule: 1px solid lightgray;
}column-width suggests a column width. The browser works out how many columns fit and adjusts their widths. A narrow container can have one column smaller than the suggested width.
column-gap sets the space between columns. column-rule draws a dividing line in that gap without adding extra width. To request a particular number instead, use a declaration such as column-count: 2.
Content continues down one column and then into the next; it is not a set of independent card tracks. A heading can span all columns with column-span: all. For a short grouped item, break-inside: avoid requests that it stay together when space permits.
clear places a following box below relevant preceding floats.display: flow-root lets a parent contain floats without clipping overflow.Try it yourself
HTML + CSS