How to stop content stretching across a wide screen: width caps for sections, a reading measure for text, newspaper columns and children that break out to full width.
Two kinds of cap
A page that fills a wide monitor is hard to read. Vanilla Breeze caps width in two ways, for two kinds of content.
|
Content width |
Measure |
| For | A section of mixed content: cards, forms, a hero | Running text: an article, documentation, a letter |
| Unit | rem | ch, so the cap is a number of characters per line |
| Tokens | --content-narrow (40rem), --content-normal (60rem), --content-wide (80rem) | --measure-narrow (45ch), --measure-normal (65ch), --measure-wide (80ch) |
| Layout | <layout-center> | <layout-text> or data-layout="prose" |
| Position | Centered | At the start edge, unless you add data-layout-centered |
| Also does | Adds a gutter on each side so content does not touch the screen edge | Spaces headings, paragraphs, lists and figures |
Capping a section
<layout-center> limits its width and centers itself in its parent. data-layout-max picks the cap.
data-layout-max | Cap |
narrow | 40rem |
normal (default) | 60rem |
wide | 80rem |
prose | 65ch |
The gutter is added outside the cap, so a normal center holds 60rem of content plus the gutters. data-layout-gutter sets it to none, s or l; the default is m.
Add data-layout-gap and the center also spaces its children in a column, which saves nesting a stack inside it.
<section data-layout="center" data-layout-max="wide" data-layout-gap="xl"> <h2>Routes</h2> <ul data-layout="grid">...</ul></section>
Two more modifiers: data-layout-intrinsic centers children that are narrower than the cap, and data-layout-text centers the text.
Capping text
Lines of 45 to 80 characters are comfortable to read. <layout-text>, or data-layout="prose" on an element such as <article>, holds text to that length and sets the vertical rhythm: more space before a heading than after it, extra room around figures, tables and code.
The demo changes the measure. The figure is covered in Breaking out.
<article data-layout="prose" data-layout-max="narrow"> <h1>Winter timetable</h1> <p>From the first Monday in November...</p></article>
data-layout-max | Measure |
narrow | 45ch |
normal (default) | 65ch |
wide | 80ch |
The same words mean different widths on a center and on text: narrow is 40rem on <layout-center> and 45ch on <layout-text>.
When the nearest container is under 30rem wide, the cap is released and text fills the width.
Width without the rhythm
data-measure on an <article> caps and centers it and changes nothing else. Use it when the article's children already manage their own spacing. Values: bare (65ch), narrow, wide.
<article data-measure="narrow"> ...</article>
Text in columns
<layout-columns> flows text across columns, like a newspaper. It shares the measure and rhythm of <layout-text>.
<layout-columns data-layout-column-count="2" data-layout-measure="narrow"> <h2>Service changes</h2> <p>...</p></layout-columns>
data-layout-column-count | Result |
1 | One column |
2, 3 | Up to that many columns. Fewer when a column would be narrower than 14rem. |
auto | As many columns as fit, each one measure wide (or --column-min-width, 38ch, when no measure is set) |
With a measure set, the block is capped at the column count times the measure. Lists, figures, tables and quotations are kept whole and not split across a column break, and a heading stays with the text after it.
Breaking out
A wide table or a photograph often wants more room than the text around it. Put data-bleed on a direct child of a text container and that child ignores the measure. It runs the full width of the nearest query container, which is usually the <main>, <section> or <article> the text sits in.
<main> <article data-layout="prose"> <p>Text at 65 characters.</p> <figure data-bleed> <img src="route-map.png" alt="Map of Line 4 from Central Station to the harbour" /> </figure> <p>Text at 65 characters again.</p> </article></main>
- It works in
<layout-text>, data-layout="prose", <layout-columns>, data-layout="columns" and article[data-measure].
- The child must be a direct child. A figure inside a nested section stays at the measure.
- In columns, the child spans every column.
- The width is the container's, not the viewport's, so a bleed inside a page with a sidebar stops at the edge of the content area.
Other places a cap is set
| On |
How |
Cap |
<main> | class="narrow" | The normal measure, centered |
<main> | class="contained" | 1200px, centered |
<main> | class="wide" | 1600px, centered |
<layout-card>, <layout-canvas> | data-max | narrow, normal, wide (the content widths) or prose (65ch) |
data-page-layout="article" | The template | One centered column of --content-normal |
Changing the caps
Set the tokens to change every place that reads them.
:root { --content-normal: 68rem; --measure-normal: 70ch;}
Under data-fluid, the fluid preset sets --content-normal and --measure-normal so that they grow with the viewport. The library's styles sit in cascade layers and your own unlayered CSS outranks them, so a rule like the one above fixes the two tokens at your values and the preset no longer moves them.