brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: container-type: inline-size lets css components respond to their own width

Css
~/tips/tip-css-container-query-inline-size

.card-wrap { container-type: inline-size; }

Lets a component change its layout based on the width of its parent instead of the browser window.

I like components that adapt to the box they sit in, not to the whole viewport.

.card-wrap { container-type: inline-size; }
@container (min-width: 30rem) {
  .card { display: grid; grid-template-columns: 8rem 1fr; }
}

container-type: inline-size turns the wrapper into a query container, and @container rules then match against its width. The same card can be stacked in a sidebar and side by side in the main column without a single media query. The container cannot be sized by its own children on the inline axis, so give it a width from its parent, and only the descendants of the container can react to the query, never the container itself.

Further reading: MDN: CSS container queries

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link