In addition to my first look + demo at Container Queries, both Andy Bell and Ahmad Shadeed have also published posts covering them.
~
Ahmad starts off with explaining the idea behind them, before digging into a ton of use-cases. I especially like the pagination use-case, something I hadn’t thought of yet myself.
~
In his post, Andy taps into a — not yet existent — cw
unit, where 1cw
equals 1% of the container. This comes in handy for tweaking the font-size
based on the available space.
/* Before */
h1 {
font-size: clamp(
var(--fluid-type-min, 1rem),
calc(1rem + var(--fluid-type-target, 3vw)),
var(--fluid-type-max, 1.3rem)
);
}
/* After */
h1 {
font-size: clamp(
var(--fluid-type-min, 1rem),
calc(1rem + var(--fluid-type-target, 5cw)),
var(--fluid-type-max, 1.3rem)
);
}
Yes, we totally need this type of unit!
Update 2021.09.21: The unit is here. Say hello to the qw
and family
~
Container Queries are Actually Coming (by Andy) →
Say Hello To CSS Container Queries (by Ahmad) →