Saltar al contenido principal
← 🎨 CSS as a design system·Módulo B6 · Lección 3
TareaBuild a hero block using clamp() for both padding and font-size. .hero { padding: clamp(2rem, 8vw, 6rem); background: #18181B; color: white; } .hero h1 { font-size: clamp(2rem, 6vw + 1rem, 5rem); margin: 0; }.

abrazadera() en todas partes: dimensionamiento de fluidos sin consultas de los medios

75 XP6 min
Teoría

clamp() recap from B4 — now applied broadly

h1 { font-size: clamp(2rem, 5vw + 1rem, 4rem); }
.section { padding: clamp(2rem, 8vw, 6rem); }
.container { width: clamp(320px, 90%, 1200px); }
.gap { gap: clamp(0.5rem, 2vw, 1.5rem); }

Anything that's a LENGTH — font-size, padding, margin, width, gap — can be a clamp(). The middle value is the "preferred" growth curve; the min and max bound it.

The recipe

For "X on small screens, Y on large":

clamp(X, X + (Y-X) * vw_scale, Y)

Or use a calculator (juniorconsult.dev/fluid-calculator) and never math again.

When NOT to use clamp

  • When the value MUST be a specific pixel value (borders, focus rings).
  • When the value MUST snap to integer pixels (font-size sometimes — sub-pixel rendering inconsistencies on some platforms).
  • When the value depends on PARENT width (use @container instead — clamp is viewport-based).

Mix with @container

Inside an @container block, you can still use clamp:

@container (min-width: 400px) {
  .card { padding: clamp(16px, 3cqw, 32px); }   /* cqw = container-query-width */
}

cqw is "container query width unit" — 1cqw = 1% of the container's width. Combine clamp + cqw for the most flexible fluid sizing.

🔒

Regístrate para empezar a programar

La teoría está abierta a todos. El editor, la vista previa y el check se desbloquean con una prueba gratis de 7 días — se requiere tarjeta, cancela cuando quieras.

Registrarse — prueba gratis →

Las primeras 10 lecciones de cada ruta son gratis. No se necesita tarjeta.

← AnteriorSiguiente lección →

Recibe un consejo de Python o web al día — por email

Corto, escrito a mano, sin spam. Anula la suscripción en un clic.