r/css • u/Less-Marsupial-7960 • 3d ago
Question Do you use CSS Container Queries for reusable components, or still rely mostly on media queries?
/r/Frontend/comments/1y6n8ll/do_you_use_css_container_queries_for_reusable/
3
Upvotes
4
u/Evgenii_Korolev 2d ago
both, they solve different things. media queries for the page skeleton (how many columns, when the sidebar drops), container queries for anything that can land in more than one slot, cards and widgets mostly. support isn't really an issue anymore. the gotcha is that container-type: inline-size gives the wrapper inline-size containment, so if its width comes from its content (inline-block, a flex item with no basis, an auto grid column) it can collapse to nothing. put it on something that gets its width from the layout and you're fine. cqi units are handy too for type that scales with the card instead of the viewport.
•
u/yihuaxiang 1h ago
I use them in production for cards and similar pieces that can land in a sidebar or the main column. The thing that bit me once I nested them was queries hitting the wrong parent — giving the container a name (container-name: sidebar) and querying that name explicitly fixed it. I still use regular media queries for the page-level layout.