Basic

One page, many widths

A page has to work at a phone width and a desktop width, and the work is the same at both if you build it right. Fluid widths, a max width, and a media query for the real change cover most designs without a second stylesheet.

What you will see

The column is still 90 percent and the text wraps. If anything overflows, that is the bug to fix at this width, not at the desktop.

About 1 min of reading

Try It

Make a column that caps itself.

1

Fluid with a cap

.col { width: 90%; max-width: 68ch; }

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The column shrinks with the window and stops growing at 68 characters, which is the readable line length.
2

Check the narrow end

resize the window to 360 pixels wide

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The column is still 90 percent and the text wraps. If anything overflows, that is the bug to fix at this width, not at the desktop.

Data Flow

The layout adapts to the window.
1 Size columns as percentages
↓
2 Cap the reading width
↓
3 Add a query at the real break
↓
4 Test narrow and wide
Why this works
Text is the constraint

A line of text under about 45 characters reads well and over about 90 it does not. That limit, not the device width, is what decides a column's maximum, and it is the reason a max width belongs on the text.

Tap targets

A link that is a few pixels tall is hard to hit on a touch screen. Padding around the target grows it without changing the design, which is the fix rather than a different control.

Examples

Percent and max width

A column at a percentage of its container shrinks with the window. A max width stops a line of text becoming unreadably wide on a large screen. Those two together give a layout that needs no breakpoints.

Media queries for real changes

Change the layout at the width where it genuinely stops working, not at the width where it looks nicer. A layout that survives to 380 pixels needs one query, not four.

Test the narrow width first

Build at the small width and grow. A design that works narrow and grows is easier than one built wide that has to be squeezed, and the squeeze is where the failures are.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Placing things side by side
Previous Lesson
Placing things side by side
Next Lesson
Finding why a style is wrong
Finding why a style is wrong →