EniunEniunEniunEniun
  • Contact
  • EN
  • ES
✕
Sin resultados Ver todos los resultados

CSS Float Problems and How to Fix Them

  • Inicio
  • CSS for Beginners
  • CSS Float Problems and How to Fix Them
01/12/2026
Ilustración de elementos flotantes que desbordan su contenedor y la solución con clear

Floats are useful for wrapping text around an image, but can cause confusing results when used as a layout system. Three recurring problems are a parent that appears too short, a following section that starts alongside a float, and floated items that no longer fit on one row.

Contenidos del artículo

Toggle
  • 1. The container does not enclose its floats
  • 2. The next section starts too early
  • 3. Floating columns no longer line up
  • 4. The clearfix pattern
  • Original CodePen examples

1. The container does not enclose its floats

A normal block may ignore its floated children when calculating its height. Establish a new block formatting context on the parent with display: flow-root.

.figure-wrap { display: flow-root; }
.figure-wrap img { float: left; margin: 0 1rem 1rem 0; }

2. The next section starts too early

If a following block should begin below an earlier float, give it clear: both, or use clear: left or right if only one side matters. This solves a different problem from containing floats inside their parent.

3. Floating columns no longer line up

Floats can fall to the next line when their combined widths, margins, borders, or padding exceed the available space. Inspect the computed sizes and check the narrowest viewport. For columns, consider Flexbox for a row or Grid for two-dimensional alignment.

4. The clearfix pattern

On a legacy layout, add a generated block after the content and clear it. Put the class on the parent that contains the floats.

.clearfix::after {
  display: block;
  clear: both;
  content: "";
}

Use the positioning guide to compare float, clear, and normal flow.

Original CodePen examples

  1. Open example 1
  2. Open example 2
  3. Open example 3
Servicios

Desarrollo Web
Diseño Web
Marketing Digital
Social Media
Experiencia de Usuario
Cursos formativos
Services

WordPress development (in Spanish)
Custom software (in Spanish)
Web design (in Spanish)
UX consulting (in Spanish)
SEO and GEO (in Spanish)
Courses and tutorials
Contacta con nosotros

info@eniun.com

Reportar un error

                   

Get in touch

Contact Eniun


info@eniun.com

Report an issue (in Spanish)

                   

Suscríbete

Únete a nuestra comunidad para recibir contenido exclusivo y relevante para diseñadores y desarrolladores web


Apuntarme

Subscribe to the newsletter

Get updates on web design, development, and computing from Eniun. The newsletter is in Spanish.


Sign up (in Spanish)
Katadoku retos de logica y deduccion
Simulador montaje PC
© 2026 Eniun | Política de privacidad y cookies
© 2026 Eniun | Privacy and cookies policy
    EN
    • EN
    • ES