Перейти к основному содержимому
← 🎨 CSS as a design system·Модуль B2 · Урок 2
ЗаданиеDemonstrate the ONE legitimate use of float: text wrapping around a pull-quote. <p> has a <span class='pullquote'>...</span> + several sentences of body text. Float the pullquote right with width 200px and margin '0 0 16px 24px'.

Float: для чего он нужен, почему мы его больше не используем

60 XP6 min
Теория

A 25-year-old layout tool

float: left was the ONLY way to do multi-column layouts from 1996 until flexbox shipped in 2014. Every grid system (Bootstrap 1-3, 960.gs, Foundation 4) was built on float hacks.

.sidebar { float: left; width: 30%; }
.main { float: right; width: 70%; }

The element is pulled out of normal flow and pushed to the left or right edge of its container. Following content wraps AROUND it.

Why floats fell out of favor

  • Container collapse — a parent with only floated children has zero height (you needed "clearfix" hacks).
  • Vertical alignment was nearly impossible.
  • Equal-height columns required JavaScript or CSS tricks.
  • The intent ("floats" were originally for text-wrap around images) never matched "put two columns next to each other."

Flexbox solved all of this in 2014. Grid added the second axis in 2017. Modern CSS doesn't need float for layout.

When float is STILL the right tool

ONE case: wrapping text around an image (or pull-quote).

.pullquote {
  float: right;
  width: 200px;
  margin: 0 0 16px 24px;   /* gap so text doesn't crowd */
}

That's it. Outside this exact case, use flexbox or grid.

🔒

Зарегистрируйся чтобы кодить

Теория открыта всем. Интерактивный редактор, живой превью и проверка открываются с 7-дневным бесплатным trial — нужна карта, отмена в любое время.

Регистрация — бесплатный trial →

Первые 10 уроков в каждом треке — бесплатные. Карта не нужна.

← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.