State history
A score that remembers its last value and which way it moved.
A card reads its own measured width, and its text follows.
Drag the slider, or focus it and use the arrow keys. Narrow the window to see the measured width differ from the slider value.
| name | value | previous | changes |
|---|---|---|---|
| Waiting for the preview to start. | |||
element(width) gives an element its own measured width as a CSS length. The text inside the card is sized from that measurement, not from the slider value, so it also follows when the card is limited by the available space.
Container queries and container units (cqw) size content from a container and are usually the better tool. element() measures the element itself, which container units cannot.
var(--w, 300px) gives a fallback for that first frame.width: calc(element(width) + 10px)): the runtime detects that loop and freezes the value./* ---- Reactive CSS -------------------------------------------------------------------------- */.size { --width: state(300); }/* The slider sets the section's state at each input. */.size .width:on(input) { --width: set(event(value-as-number)); }.size .set { content: var(--width); }.size .card { width: min(var(--width) * 1px, 100%); --w: element(width); /* the card's own border-box width */}.size .big { font-size: calc(var(--w, 300px) / 6); } /* follows the measured width */.size .measured::after { counter-reset: w round(var(--w, 0px) / 1px); content: counter(w); }Source: site/src/catalog/api/element-size/. style.css from its Reactive CSS divider; the layout above it and the shared api.css run but are not shown.
A score that remembers its last value and which way it moved.
Right-click anywhere on the desk to open a custom menu where you clicked.