Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 6.4 — Floats and Clearing
CSS · Example 3 of 3

clear: none, left and both

With clear: none the block slides up to the top, under the floats (its text squeezes between them). clear: left moves it below the 40px left float; clear: both below the 80px right float too. The flow-root wrapper always grows to fit.

float pushes a box to the left or right edge of its container and lets text and inline content wrap around it; floats leave normal flow, so parents collapse unless you contain them with display: flow-root, and clear moves a box below earlier floats.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Float an <img class="avatar"> to the right of a paragraph, 100px wide, with a 12px gap between it and the text.

02

A .gallery contains only floated thumbnails and its border collapses. Fix it without clipping and without changing the thumbnails.

03

A .footer slides up beside a left-floated .sidebar. Make it start below the sidebar.

Explain it without notes

01

What does float do to a box and to the content after it?

02

Why does a parent containing only floats collapse, and what are the ways to fix it?

03

What does clear: both do?

04

What is a block formatting context, and how does display: flow-root relate to floats?

clear: none, left and both

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

clear: none -> top 0 | wrap height 80
clear: left -> top 40 | wrap height 80
clear: both -> top 80 | wrap height 100