A single card component, resized live, reacting to its container instead of the viewport. Most CSS problems we see in reviews are not about a missing property. They are about a layout that was never told what it should do when the content changes size, and that is what this piece sets out to fix.
Sample footage: a CC0 clip from the MDN Web Docs example media.
Start from the constraint
Begin by writing down the smallest and largest sizes the component must survive. Once those two numbers exist, properties such as clamp(), minmax(), and fit-content stop feeling like magic and start reading like a specification.
- Set explicit minimum and maximum sizes first.
- Prefer intrinsic sizing keywords over fixed pixel values.
- Let the container decide, not the viewport.
- Keep one fallback declaration above the modern one.
The tricky part is always the middle: the tablet widths nobody designs for, the translated label that is forty percent longer, the avatar that failed to load. Test those states on purpose by resizing the container rather than the whole window.
None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.
As always, the examples are simplified to fit on a page. The production version has more error handling and logging, but the shape of the code is the same.
Questions, corrections, and war stories are welcome in the comments. Several of our best follow-up posts started as a reader pointing out something we had missed.
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.
Tim Berners-Lee, W3C Web Accessibility Initiative launch, 1997
Comments 0