Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Responsive Behavior

How each layout adapts to narrow space: which ones wrap by themselves, which follow their container, which follow the viewport and how to change the point where they switch.

Layouts respond to their own space

A component does not know where it will be used. A card grid might fill the page today and sit in a 20rem sidebar tomorrow. A viewport breakpoint cannot tell those apart, so most layouts in Vanilla Breeze do not use one. They look at the width they have been given and wrap or stack when it runs out.

The demo holds four layouts in one box. The buttons change the width of the box and nothing else. The browser window stays the same size, so no media query fires.

There are three mechanisms. The table says which layout uses which.

Layout Responds to What happens
ClusterIts own widthItems wrap to a new line
GridIts own widthDrops columns one at a time, down to one
SwitcherIts own widthAll children in one row, or all stacked, below 30rem
SidebarIts own widthThe two columns wrap when the content column would get less than half the width
ColumnsIts own widthFewer text columns, down to one
ReelNothingNever wraps. It scrolls sideways at every width
MediaNearest containerThe figure moves above the text when the container is under 25rem
Prose, text, columnsNearest containerThe line-length cap is released when the container is under 30rem
Sidebar inside a page layout's <main>The region-main containerEach child takes a full row when main is under 40rem
SplitViewportOne column below 48rem
<main data-layout="sidebar-left"> and sidebar-rightViewportOne column below 48rem, in the order article, aside, nav
Page layoutsViewportSidebar templates become one column below 48rem; the dashboard nav becomes a drawer; the app shell nav moves to the bottom

Layouts that size themselves

These use flexbox and grid rules that depend on the layout's own width. No query is involved, so they work at any nesting depth.

Grid

A grid makes as many columns as fit, each at least data-layout-min wide, then shares the leftover space between them. When the grid is narrower than one minimum, the single column shrinks to fit and does not overflow.

data-layout-minSmallest column
xs8rem
s10rem
m (default)15rem
l20rem
xl25rem

For a width between the steps, set the --layout-min custom property on the grid.

Switcher

A switcher keeps its children in one row while it is wider than its threshold, and stacks them all when it is narrower. There is no in-between state with two on one line and one below.

AttributeEffect
data-layout-thresholdThe width where it switches: s (25rem), m (30rem, the default), l (40rem). For another width, set --layout-threshold.
data-layout-limit2, 3 or 4. With more children than the limit, the switcher stacks at every width.
data-layout-reverseReverses the visual order when stacked, so the last child is on top. The row keeps source order.

The sidebar column asks for a fixed width and the content column takes the rest. When the content would get less than its minimum share of the row, the two wrap and each takes the full width.

AttributeEffect
data-layout-sidebar-widthThe sidebar column: narrow (12rem), normal (16rem, the default), wide (20rem)
data-layout-content-minThe content column's smallest share before wrapping: s (40%), m (50%, the default), l (60%). For another value, set --layout-content-min.
data-layout-nowrapNever wrap

With the defaults and a gap of m, the sidebar wraps when the layout is narrower than about 34rem.

Columns

With data-layout-column-count="2" or "3" the count is a maximum. A column is never narrower than 14rem, so three columns become two and then one as the element narrows. With "auto" the browser fits as many columns of the measure as it can.

Layouts that follow a container

A container query asks how wide an ancestor is. Vanilla Breeze makes every <main>, <article>, <section> and <aside> a query container (container-type: inline-size), so a query usually has something close by to measure.

The library's own container queries are few: the media object stacks under 25rem, the reading measure is released under 30rem, and a sidebar in a page layout's main stacks when main is under 40rem. The containers matter more for the CSS you write.

Named regions

Inside a data-page-layout, the regions have container names, so a query can ask about the main region in particular and not whichever container is nearest.

The names are region-main, region-nav and region-aside. Grid Identity lists them with the names used inside a main-level sidebar.

Where a sectioning element is not a container

A size container has no width of its own: it takes the width its parent gives it. Where a layout sizes children by their content, a container child would collapse to nothing, so the library turns containment off for <main>, <article>, <section> and <aside> children in these places:

  • Direct children of a cluster or a reel.
  • Direct children of a cover with data-layout-centered.
  • Direct children of a stack with data-layout-align set to start, center or end.
  • Direct children of a grid with data-layout-subgrid, because containment breaks subgrid.
  • An article with data-numbered or data-section-numbers, and the sections inside it, because containment restarts CSS counters.
  • A floated aside (aside.float, aside.sidenote) and any element with the popover attribute.

A query inside one of these measures the next container out. To make the element a container anyway, add data-container, and give it a width if its parent sizes it by content.

You can put data-container on any other element too. With no value the container has no name. The values card, panel and media name it.

Layouts that follow the viewport

Page structure is the one place where the viewport is the right thing to ask. The page templates, the main-level sidebars and data-layout="split" switch to one column below 48rem. Add data-layout-nowrap to keep the wide shape.

The library uses four viewport widths. They are published as tokens for reference. A custom property cannot be used inside a media query, so write the value in your own queries.

TokenValueUsed for
--bp-s37.5remCompact phones. Below this a canvas surface goes flush to the edges.
--bp-m48remThe split between one column and several. Page layouts, main-level sidebars and split collapse below it.
--bp-l64remDesktop layouts. The page table of contents becomes sticky from this width when data-sticky is on.
--bp-xl87.5remThe widest pages. The holy-grail and dashboard page layouts stop growing here.

Check the stacked order

When a layout stacks, the children appear in source order, with three exceptions:

  • A switcher with data-layout-reverse stacks last child first.
  • A <main data-layout="sidebar-left"> stacks as article, aside, nav, so a nav that comes first in the source is shown last.
  • A sidebar with data-layout-side="end" shows its <nav> or <aside> after the content at every width.

Keyboard focus and screen readers follow the source in every case. Write the source in the order the page should be read, and use these only where the visual change does not alter the meaning.

↑